Guest User

Untitled

a guest
Aug 21st, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 KB | None | 0 0
  1. Error when updating a table adapter in Visual Basic
  2. 'Open connection
  3. Using Conn as new OleDbConnection("connection string")
  4.  
  5. 'This is the command that will update your table in the database
  6. Using UpdateCmd = Conn.CreateCommand()
  7.  
  8. UpdateCmd.CommandText = "update yourtable set col1 = ?, col2 = ?"
  9.  
  10. 'Create a parameter to pass in the value of the "col1" column on "yourtable"
  11. Dim ColOneParam = UpdateCmd.Parameters.Add("@Col1", OleDbType.Integer)
  12. ColOneParam.SourceColumn = "Name of column in DataTable which corresponds to col1"
  13.  
  14. 'Create a parameter to pass in the value of the "col2" column on "yourtable"
  15. Dim ColTwoParam = UpdateCmd.Parameters.Add("@Col2", OleDbType.Integer)
  16. ColTwoParam.SourceColumn = "Name of column in DataTable which corresponds to col2"
  17.  
  18. 'Data adapter which will perform the specified update command for each
  19. 'newly inserted row
  20. Using Adapter As New OleDbDataAdapter
  21.  
  22. 'Set the update command on the adapter, if you omit this line you'll
  23. 'encounter the original error you mentioned
  24. Adapter.UpdateCommand = UpdateCmd
  25.  
  26. 'This is the data table containing the rows you wish to update
  27. Dim NewRows As New DataTable("SomeTable")
  28.  
  29. 'For each modified row in NewRows, update it in the database
  30. Adapter.Update(NewRows)
  31.  
  32. End Using
  33.  
  34. End Using
  35.  
  36. End Using
Add Comment
Please, Sign In to add comment