Anton Agapov
Anton Agapov

Reputation: 142

How to filter datatable rows in debug mode

I wrote an application which is working with strongly typed datasets and adapters.

First it reads data from database and store it to the typed datatable.Second this datatable processed by this application (add, delete or update rows) and last writes updated data back to the database.

On the step of updating sometimes application causes the exception of

Violation of PRIMARY KEY constraint 'PK_GPS_Events_History'. Cannot insert duplicate key in object 'dbo.GPS_Events_History'. The duplicate key value is (16805552).

The statement has been terminated."} System.Exception {System.Data.SqlClient.SqlException}

Table GPS_Events_History at the moment of exception contains about ~30000 rows. How to filter data in datatable to look at this single row with ID=16805552? I tried to filter it by following code:

dataTable.where(row => row.ID == 16805552)

but VS2010 didn't allow me to enter any LINQ expression in debugger variables window.

Upvotes: 0

Views: 994

Answers (2)

Anton Agapov
Anton Agapov

Reputation: 142

I typed following command in quick watch window and it solved the problem:

Select("ID = 16805552")

Upvotes: 0

gunr2171
gunr2171

Reputation: 17579

Make the result you want to debug save to a variable, then inspect the variable:

var testData = dataTable.Where(row => row.ID == 16805552);
//once the line above has executed, quickwatch the "testData" variable

You can't put lambdas in a quickwatch window, so this is the next best thing.

Upvotes: 1

Related Questions