Link to home
Start Free TrialLog in
Avatar of bman9111
bman9111

asked on

C# return updated rows

I am using

command.ExecuteNonQuery()


is there anyway to have it return the 1st fields of the updated table.

ASKER CERTIFIED SOLUTION
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of bman9111
bman9111

ASKER

I am running a global update to a table. and wanted to see what records were touched...I know u can have it return rows affected...

The only other way that I can see is do a select query of the data then through the reader do an update and save to a variable the records touched...I really just wanted to run one sql command which is the update command and that was it...


if you only want to know the number of rows affected, the ExecuteNonQuery has an overload which accepts a parameter that returns that information.

can u tell me how it would do that ...All i want is the 1st field listing or affected rows...thats it...

so there is no way to have it return the 1st field data of the number of affected rows???

meaning if I have the following


field1     field2
dog        pet
cat         pet
gate       part

and the update script update the fields dog and cat...

that after the update command the return values would be
dog
cat

I want to confirm angelIIIs statement: This is NOT possible with ExecuteNonQuery().

What you want IS a query. You can't use NON-query at one hand, and expect it to behave like a query on the other hand :)

I strongly assume that you have a where-clause in your sql-statement to ExecuteNonQuery(). Thus, I suggest you do your ExecuteNonQuery() and then, as a second step, perform a query with the same where-clause. That will return you the data of the affected rows.