Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

RowNotInTableException on Delete Using SqlDataAdapter

Status
Not open for further replies.

andrea96

Programmer
Jan 26, 2001
201
US
I am getting a RowNotInTableException with this error message when I attempt to delete a row from my database using a SqlDataAdapter.

This row has been removed from a table and does not have any data. BeginEdit() will allow creation of new data in this row.
My dataset is bound to a grid, and I delete the row by deleting a row on the grid.

Here is my code to build the DeleteCommand.
Code:
cmdComponents = New SqlCommand
With cmdComponents
    .Connection = cnnComponents
    .CommandType = CommandType.StoredProcedure
    .CommandText = "aih_clDeleteKitComponents"
    .Parameters.Add(New SqlParameter("@KitNo", SqlDbType.VarChar, 30, "kit_no"))
    .Parameters.Add(New SqlParameter("@SequenceId", SqlDbType.Int, 4, "sequence_id"))
End With
daComponents.DeleteCommand = cmdComponents
My stored procedure executes correctly in Query Analyzer.

I found something on the web that said this error could be caused by the delete command reading from the current dataset values instead of the original. So, I created a dataview of the dataset and can see that the original values are in the dataview just before the sqldataadapter.update is executed.

I'm running out of ideas, so any help would be appreciated.

Thanks,
Andrea
 
I figured out my problem. I was handling the RowChanged event for the DataSet table in a form. The code in the handler was trying to access some of the row values, causing the exception. I added a statement to check for a Detached RowState in the handler, and that fixed the problem.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top