I am no success update my 2rd datagridview database....can some one help me take a look

  • Thread starter Thread starter christing
  • Start date Start date
C

christing

Guest
I have doing 2 datagridview 1st success but the second once i face this issue (There is no row at position 0). I am strange why i using same method on my 2rd datagridview will face the problem (There is no row at position 0).Can someone help me take a look. below is my button edit coding.the purpose i doing 2rd datagridview is if my user want to edit the some privacy data the user need login 1st b4 edit the privacy data. i have 2 data table 1st is keep normal data 2rd is privacy data table

Private Sub Edit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Edit.Click

LoginForm.boolresetPassword = True
LoginForm.ShowDialog()

'check for the selected item in list
Dim cmd As New OleDb.OleDbCommand
If Me.DataGridView1.Rows.Count > 0 Then
If Me.DataGridView1.SelectedRows.Count > 0 Then
Dim intcid1 As Integer = Me.DataGridView1.SelectedRows(0).Cells("ID").Value
'get data from database followed by checker id
'open connection
If Not cnn.State = ConnectionState.Open Then
cnn.Open()
End If
'get data into datatable
Dim da As New OleDb.OleDbDataAdapter("SELECT * FROM stock " & _
" WHERE checkercid=" & intcid1, cnn)

Dim dt As New DataTable
da.Fill(dt)
Me.txtdetail1.Text = dt.Rows(0).Item("txtdetail1")


'change button add to update
Me.Edit.Text = "Update"
'disable button edit
Me.btnEdit.Enabled = True

cmd.CommandText = "UPDATE checker " & _
" SET" & _
", [CheckerDetail]='" & Me.txtdetail1.Text & "'" & _
" WHERE [checkercid]=" & DataGridView1("checkercid", DataGridView1.CurrentCell.RowIndex).Value
MsgBox("Update Data Successful", MsgBoxStyle.OkOnly, "Message")
cmd.ExecuteNonQuery()
End If
End If
cnn.Close()

'refresh data in list
RefreshData()
End Sub

Continue reading...
 
Back
Top