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.
command.ExecuteNonQuery()
is there anyway to have it return the 1st fields of the updated table.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
if you only want to know the number of rows affected, the ExecuteNonQuery has an overload which accepts a parameter that returns that information.
ASKER
can u tell me how it would do that ...All i want is the 1st field listing or affected rows...thats it...
ExecuteNonQuery() always returns the number of affected rows as return value:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemDataSqlClientSqlCommandClassExecuteNonQueryTopic.asp
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemDataSqlClientSqlCommandClassExecuteNonQueryTopic.asp
ASKER
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
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.
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.
ASKER
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...