views:

1444

answers:

2

I am getting a strange exception when trying to update a DataTable after flagging a row for deletion. It looks like it's validating the data in the row I'm trying to delete. I was able to save the same row successfully, why won't it let me delete it?

Using C# in VS 2008 and SQL Server CE.

The essential bits (I hope) of my code:

var listDataTable = new booksDataSet.ListDataTable();
this.tableAdapterManager1.ListTableAdapter.Fill(listDataTable);
listDataTable.Rows[0].Delete();
this.tableAdapterManager1.ListTableAdapter.Update(listDataTable);
booksDataSet1.List.AcceptChanges(); // exception here

The exception is: System.FormatException was unhandled Message="@p2 : foo - Input string was not in a correct format." Source="System.Data"

I've reduced this to a very simple table: Id (PK, int, not null) Name (nvarchar(100), not null) Notes (nvarchar(4000), null)

The data in the row I'm trying to delete (first row) is Name = "foo", so it is the correct row, but why does it care what the data is before deleting the row?

+1  A: 

You need to do a trace on the app (try running it on your local copy of SQL Server and run the 'Profiler'); my guess is when the SQL query is hitting your SQL Server, part of it isn't in the correct format. I bet you'll see the problem when you run a trace.

George Stocker
Thanks. I will try, since that sounds like a debugging technique I should know.Your answer did point me in the right direction. I opened the DataSet in the designer and checked out the Update statement for the adapter. It was wrong; I regenerated it and now it works.
Dennis
Oh, ok .
George Stocker
A: 

I get the same response. If I bind with {0:c} it will fail on delete every time. Thinking it was the $ I tried {0:N2} same response. Remove it, deletes just fine.

Davd