• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 322
  • Last Modified:

C# return updated rows

I am using

command.ExecuteNonQuery()


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

0
bman9111
Asked:
bman9111
  • 3
  • 2
  • 2
1 Solution
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
not with the ExecuteNonQuery.

Anyhow, you have to give more details about what you are trying to achieve...
0
 
bman9111Author Commented:
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...


0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
if you only want to know the number of rows affected, the ExecuteNonQuery has an overload which accepts a parameter that returns that information.

0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

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

0
 
wlfsCommented:
0
 
bman9111Author Commented:
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

0
 
wlfsCommented:
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.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

  • 3
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now