C#: Exception “Input string was not in a correct format.” after Row.Delete in DataSet

csql serversql-server-ce

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?

Best Answer

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.

Related Topic