Hello
I am new to VB.net and have a form where I am trying to update an Access database from a datagridview that I databound on the fly. However when I change something on the grid and press the update button it would seem that the dataset has accepted the changes, but when I next look at the grid, it hasn't updated. Can I use a SELECT statement in the way that I have?
Am I doing something wrong in the code, or is there something in the grid properties that I need to change?
Many thanks
Trimtrom
Public Class frmManual
Dim dcManual As New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\Nwind 97.mdb")
Dim daManual As OleDb.OleDbDataAdapter
Dim dsManual As New DataSet
Dim strSQL As String
Private Sub frmManual_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
strSQL = "select * from employees"
Try
daManual = New OleDb.OleDbDataAdapter(strSQL, dcManual)
daManual.Fill(dsManual, "Employees")
Catch ex As Exception
MsgBox(ex.Message)
End Try
Me.dgManual.DataSource = dsManual.Tables("Employees")
End Sub
Private Sub cmdUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdUpdate.Click
Dim ans As String
If (dsManual.HasChanges) Then
ans = MsgBox("Changes have occurred!" & vbCrLf & "Do you wish to update?", MsgBoxStyle.YesNo + MsgBoxStyle.Information, "Updates")
If ans = vbYes Then
Try
dsManual.AcceptChanges()
daManual.Update(dsManual.Tables("Employees"))
Catch exManual As Exception
MsgBox(exManual.Message)
Throw exManual
Finally
End Try
MsgBox("Table updated!", MsgBoxStyle.Critical, "Employees")
End If
End If
End Sub
End Class
I am new to VB.net and have a form where I am trying to update an Access database from a datagridview that I databound on the fly. However when I change something on the grid and press the update button it would seem that the dataset has accepted the changes, but when I next look at the grid, it hasn't updated. Can I use a SELECT statement in the way that I have?
Am I doing something wrong in the code, or is there something in the grid properties that I need to change?
Many thanks
Trimtrom
Public Class frmManual
Dim dcManual As New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\Nwind 97.mdb")
Dim daManual As OleDb.OleDbDataAdapter
Dim dsManual As New DataSet
Dim strSQL As String
Private Sub frmManual_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
strSQL = "select * from employees"
Try
daManual = New OleDb.OleDbDataAdapter(strSQL, dcManual)
daManual.Fill(dsManual, "Employees")
Catch ex As Exception
MsgBox(ex.Message)
End Try
Me.dgManual.DataSource = dsManual.Tables("Employees")
End Sub
Private Sub cmdUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdUpdate.Click
Dim ans As String
If (dsManual.HasChanges) Then
ans = MsgBox("Changes have occurred!" & vbCrLf & "Do you wish to update?", MsgBoxStyle.YesNo + MsgBoxStyle.Information, "Updates")
If ans = vbYes Then
Try
dsManual.AcceptChanges()
daManual.Update(dsManual.Tables("Employees"))
Catch exManual As Exception
MsgBox(exManual.Message)
Throw exManual
Finally
End Try
MsgBox("Table updated!", MsgBoxStyle.Critical, "Employees")
End If
End If
End Sub
End Class