C# SqlCommandBuilder not performing delete
Im going insane trying to figure this one out.
Im populating a DataTable from my database.
A DataGridView DataSource is set to my DataTable.
I insert, update and delete rows from the DataTable which in turn updates the DataGridView.
Im using the below to update my changes back to the database where i pass in the modified DataTable.
Insert and Update are working but Delete does not remove the deleted rows from the database table.
I hardly ever use the dataadapter- I use straight up cmd objects and stored procs... but...
so that delete command you posted... I assume that is captured off a break point on myAdapter.DeleteCommand = etc ?
so my question is this... that is not a valid sql statement...
That SQL is retrieved by using MessageBox.Show(myAdapter.DeleteCommand.CommandText);
I believe the SqlCommandBuilder automatically replaces the @p values with actual values when it runs.
The update and inserts show the same @p values but they work fine.
Finally figured it out.
When deleting the rows from the datatable i was using:
This completly removes it from the datatable so when the SqlCommandBuilder came around to deleting it from the database it never knew it existed in the first place.
For it to work you need to flag the row as deleted but not actually delete it.
By doing this it all worked.
|All times are GMT +1. The time now is 09:19 AM.|
Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.