VinceC
Member
Can anyone tell me why this code is not updating my table?
Thanks.
Code:
Dim MyConnStr As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Test.mdb"
Dim MyConn As OleDb.OleDbConnection = New OleDb.OleDbConnection(MyConnStr)
Dim MySelectStr As String = "SELECT * FROM MyTable"
Dim MySelectCmd As OleDb.OleDbCommand = New OleDb.OleDbCommand(MySelectStr, MyConn)
Dim MyUpdateCmd As OleDb.OleDbCommand = New OleDb.OleDbCommand()
Dim MyUpdateStr As String = "UPDATE MyTable SET Name=""Maria"" WHERE ID=2"
MyUpdateCmd.CommandText = MyUpdateStr
MyUpdateCmd.Connection = MyConn
MyUpdateCmd.Parameters.Add(New OleDb.OleDbParameter("Name", OleDb.OleDbType.VarWChar, 50, "Name"))
MyUpdateCmd.Parameters.Add(New OleDb.OleDbParameter("Original_ID", OleDb.OleDbType.Integer, 0, ParameterDirection.Input, False, CType(10, Byte), CType(0, Byte), "ID", DataRowVersion.Original, Nothing))
Dim MyDBAdapter As OleDb.OleDbDataAdapter = New OleDb.OleDbDataAdapter()
MyDBAdapter.SelectCommand = MySelectCmd
MyDBAdapter.TableMappings.AddRange(New Common.DataTableMapping() {New Common.DataTableMapping("Table", "MyTable", New Common.DataColumnMapping() {New Common.DataColumnMapping("ID", "ID"), New Common.DataColumnMapping("Name", "Name")})})
MyDBAdapter.UpdateCommand = MyUpdateCmd
Dim MyDS As DataSet = New DataSet()
MyDBAdapter.Update(MyDS, "Table")
Thanks.