Skip to content
Advertisement

update command C# DataGridView to SQL

I’m attempting to update a SQL table from C# project datagridview “Work_Table”. However when I attempt to make the update I get this error

“Update unable to find TableMapping [‘Work_Table’] or DataTable ‘Work_Table'”

Any ideas?

Here is my code below:

Advertisement

Answer

You need to retrieve the DataTable from the .DataSource property of the grid. This will have the information on what was added, updated and deleted.

You can skip the command and pass the select string and connection string directly to the DataAdapter constructor.

Create a CommandBuilder to provide the Insert, Update and Delete text for the DataAdapter.Update. Pass the DataAdapter to the constructor of the CommandBuilder.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement