Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Error when updating a table adapter in Visual Basic
- 'Open connection
- Using Conn as new OleDbConnection("connection string")
- 'This is the command that will update your table in the database
- Using UpdateCmd = Conn.CreateCommand()
- UpdateCmd.CommandText = "update yourtable set col1 = ?, col2 = ?"
- 'Create a parameter to pass in the value of the "col1" column on "yourtable"
- Dim ColOneParam = UpdateCmd.Parameters.Add("@Col1", OleDbType.Integer)
- ColOneParam.SourceColumn = "Name of column in DataTable which corresponds to col1"
- 'Create a parameter to pass in the value of the "col2" column on "yourtable"
- Dim ColTwoParam = UpdateCmd.Parameters.Add("@Col2", OleDbType.Integer)
- ColTwoParam.SourceColumn = "Name of column in DataTable which corresponds to col2"
- 'Data adapter which will perform the specified update command for each
- 'newly inserted row
- Using Adapter As New OleDbDataAdapter
- 'Set the update command on the adapter, if you omit this line you'll
- 'encounter the original error you mentioned
- Adapter.UpdateCommand = UpdateCmd
- 'This is the data table containing the rows you wish to update
- Dim NewRows As New DataTable("SomeTable")
- 'For each modified row in NewRows, update it in the database
- Adapter.Update(NewRows)
- End Using
- End Using
- End Using
Add Comment
Please, Sign In to add comment