View Single Post
Old 02-13-2013, 08:46 PM   PM User | #1
brokenarrows
New to the CF scene

 
Join Date: Feb 2013
Posts: 4
Thanks: 0
Thanked 2 Times in 1 Post
brokenarrows is an unknown quantity at this point
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.

Code:
private static void updateDatabase(DataTable dt)
{
    SqlDataAdapter myAdapter = new SqlDataAdapter();
    SqlCommand myCommand = new SqlCommand("SELECT * from dbo.DisplayList", sqlCon);
    SqlCommandBuilder myCommandBuilder = new SqlCommandBuilder(myAdapter);

    myAdapter.SelectCommand = myCommand;

    myAdapter.InsertCommand = myCommandBuilder.GetInsertCommand();
    myAdapter.UpdateCommand = myCommandBuilder.GetUpdateCommand();
    myAdapter.DeleteCommand = myCommandBuilder.GetDeleteCommand();

    myAdapter.Update(dt);
}
The myAdapter.DeleteCommand.CommandText is:
Code:
DELETE FROM [dbo].[DisplayList] WHERE (([PropertyID] = @p1) AND 
([DisplayID] = @p2) AND ([DisplayName] = @p3) AND ((@p4 = 1 AND 
[TerminalID] IS NULL) OR ([TerminalID] = @p5)))
Anyone have any ideas whats wrong with the above or to help investigation how i can find out what the @p values are being converted to?
brokenarrows is offline   Reply With Quote