elianeasmar
Well-known member
- Joined
- Oct 3, 2013
- Messages
- 76
- Programming Experience
- Beginner
Hello guys i have a problem. i have a datagridview with textboxes. i insert-update-delete records from database. Everything works fine. when i click on a cell in the grid. the information about this person are populated into the textboxes. but when i click on the newly inserted record it won't display the informations into texboxes. here is my code. What could the problem be? |
Private Sub DataGridView1_RowEnter(sender As Object, e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.RowEnter Try If e.RowIndex < 0 Then Exit Sub txtserial.Text = DataGridView1.Rows(e.RowIndex).Cells(0).Value lblcustomer.Text = "Member: " & DataGridView1.Rows(e.RowIndex).Cells("Name").Value & " " & DataGridView1.Rows(e.RowIndex).Cells("familyName").Value Dim cmd As SqlCommand Dim myDA As SqlDataAdapter Dim myDataSet As DataSet Dim strsql As String Dim i As Integer = 0 strsql = "select * from membersvw where serial = " & Val(txtserial.Text) cmd = New SqlCommand(strsql, mcon) If mcon.State = ConnectionState.Closed Then mcon.Open() myDA = New SqlDataAdapter(cmd) myDataSet = New DataSet() myDA.Fill(myDataSet, "membersvw") If myDataSet.Tables("membersvw").Rows.Count > 0 Then txtserial.Text = myDataSet.Tables("membersvw").Rows(0).Item("serial").ToString txtname.Text = myDataSet.Tables("membersvw").Rows(0).Item("name").ToString txtfamilyname.Text = myDataSet.Tables("membersvw").Rows(0).Item("familyname").ToString txtphone.Text = myDataSet.Tables("membersvw").Rows(0).Item("phone").ToString txtmobile.Text = myDataSet.Tables("membersvw").Rows(0).Item("mobile").ToString txtfax.Text = myDataSet.Tables("membersvw").Rows(0).Item("fax").ToString txtemail.Text = myDataSet.Tables("membersvw").Rows(0).Item("email").ToString txtwebsite.Text = myDataSet.Tables("membersvw").Rows(0).Item("website").ToString txtaddress.Text = myDataSet.Tables("membersvw").Rows(0).Item("address").ToString txtspace.Text = myDataSet.Tables("membersvw").Rows(0).Item("space").ToString cmbtimezone.Text = myDataSet.Tables("membersvw").Rows(0).Item("timezonename").ToString End If If TabControl1.SelectedTab.Name = "TabPage2" Then clearcars() fillcargrid() ElseIf TabControl1.SelectedTab.Name = "TabPage3" Then clearpayments() fillpaymentgrid() End If myDA.Dispose() myDataSet.Dispose() 'mcon.Close() Catch ex As Exception MsgBox(ex.ToString) End Try End Sub
Thank you for your help.