I am writing a simple program to update a access database and keeping getting a syntax error and I don't know why. Please help I have been working on this for a while now and I am well and truly stuck! The datatable updates as expected but I cant make the updates transfer to my access database, I know I am missing something I just don't know what it is!!!
Private Sub btnTest_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTest.Click
Dim Conn As New System.Data.OleDb.OleDbConnection()
Dim dsUsers = New DataSet()
Dim DAdapter = New OleDb.OleDbDataAdapter()
Dim current = frmUserEntry.UNText.Text
Dim Querystring = "select * from users"
Dim DTable As DataTable
Dim Bs As New BindingSource()
Dim myCommandBuilder = New System.Data.OleDb.OleDbCommandBuilder()
Dim drCurrent As DataRow
Conn.ConnectionString = "provider=microsoft.jet.oledb.4.0;" & "data source=h:\SmartMasterV2_4.mdb"
DAdapter.SelectCommand = New OleDb.OleDbCommand(Querystring, Conn)
dsUsers.Tables.add("Users")
DTable = dsUsers.Tables("Users")
Conn.Open()
DAdapter.FillSchema(dsUsers, SchemaType.Source, "Users") ' with schema, table knows which column is primary key, enable Find method
DAdapter.Fill(dsUsers, "Users")
Conn.Close()
Bs.DataSource = dsUsers.Tables("Users")
DGV2.DataSource = Bs
myCommandBuilder.DataAdapter = DAdapter
DAdapter.InsertCommand = myCommandBuilder.GetInsertCommand()
DAdapter.UpdateCommand = myCommandBuilder.GetUpdateCommand()
DAdapter.DeleteCommand = myCommandBuilder.GetDeleteCommand()
'BEGIN EDIT CODE
drCurrent = DTable.Rows.Find(current.ToString)
tb1.Text = current.ToString
drCurrent.BeginEdit()
drCurrent("Password") = tbNewPW.Text
drCurrent.EndEdit()
MsgBox("Record edited successfully")
Stop
Conn.Open()
Try
DAdapter.Update(dsUsers, "Users")
Conn.Close()
Catch ex As Exception
DisplayOleDbErrorCollection(ex)
End Try
End Sub
I appreciate any help you can give me,
Thank you