C
christing
Guest
I fail to update my data to my access database. can help view is i am missing something on my code. current my code no showing any error message. I have try solve many time but i still no success to solve it.
Private Sub Edit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Edit.Click
LoginForm.boolresetPassword = True
LoginForm.ShowDialog()
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
'open connection
If Not cn3.State = ConnectionState.Open Then
cn3.Open()
End If
'get data into datatable
Dim da As New OleDb.OleDbDataAdapter("SELECT * FROM stock " & _
" WHERE cid=" & intcid1, cn3)
Dim dt As New DataTable
da.Fill(dt)
Me.txtbarcode.Text = intcid1
Me.txtdetail1.Text = dt.Rows(0).Item("CheckerDetail")
Me.txtbarcode.Tag = intcid1
'change button add to update
Me.save.Text = "Update"
'disable button edit
Me.Edit.Enabled = True
End If
End If
cn3.Close()
'refresh data in list
RefreshData1()
End Sub
Private Sub save_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles save.Click
Dim cmd As New OleDb.OleDbCommand
cmd.CommandText = "UPDATE stock " & _
" SET" & _
", [CheckerDetail]='" & Me.txtdetail1.Text & "'" & _
" WHERE [ID]=" & DataGridView1("ID", DataGridView1.CurrentCell.RowIndex).Value
''" WHERE [cid]=" & Me.txtbarcode.Tag
MsgBox("Update Data Successful", MsgBoxStyle.OkOnly, "Message")
''End Try
RefreshData1()
cn3.Close()
End Sub
Private Sub RefreshData1()
If Not cn3.State = ConnectionState.Open Then
'open connection
cn3.Open()
End If
Dim da As New OleDb.OleDbDataAdapter("SELECT cid as [ID], " & _
"CheckerName as [CheckerName] , ShipQuantity as [Quantity], Date as [Date], CompanyName as [CompanyName], CheckerDetail as [CheckerDetail]" & _
" FROM stock ORDER BY cid", cn3)
Dim dt As New DataTable
'fill data to datatable
da.Fill(dt)
Me.DataGridView1.DataSource = dt
'close connection
cn3.Close()
End Sub
Continue reading...
Private Sub Edit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Edit.Click
LoginForm.boolresetPassword = True
LoginForm.ShowDialog()
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
'open connection
If Not cn3.State = ConnectionState.Open Then
cn3.Open()
End If
'get data into datatable
Dim da As New OleDb.OleDbDataAdapter("SELECT * FROM stock " & _
" WHERE cid=" & intcid1, cn3)
Dim dt As New DataTable
da.Fill(dt)
Me.txtbarcode.Text = intcid1
Me.txtdetail1.Text = dt.Rows(0).Item("CheckerDetail")
Me.txtbarcode.Tag = intcid1
'change button add to update
Me.save.Text = "Update"
'disable button edit
Me.Edit.Enabled = True
End If
End If
cn3.Close()
'refresh data in list
RefreshData1()
End Sub
Private Sub save_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles save.Click
Dim cmd As New OleDb.OleDbCommand
cmd.CommandText = "UPDATE stock " & _
" SET" & _
", [CheckerDetail]='" & Me.txtdetail1.Text & "'" & _
" WHERE [ID]=" & DataGridView1("ID", DataGridView1.CurrentCell.RowIndex).Value
''" WHERE [cid]=" & Me.txtbarcode.Tag
MsgBox("Update Data Successful", MsgBoxStyle.OkOnly, "Message")
''End Try
RefreshData1()
cn3.Close()
End Sub
Private Sub RefreshData1()
If Not cn3.State = ConnectionState.Open Then
'open connection
cn3.Open()
End If
Dim da As New OleDb.OleDbDataAdapter("SELECT cid as [ID], " & _
"CheckerName as [CheckerName] , ShipQuantity as [Quantity], Date as [Date], CompanyName as [CompanyName], CheckerDetail as [CheckerDetail]" & _
" FROM stock ORDER BY cid", cn3)
Dim dt As New DataTable
'fill data to datatable
da.Fill(dt)
Me.DataGridView1.DataSource = dt
'close connection
cn3.Close()
End Sub
Continue reading...