6

Basically I'm retrieving all the data in my program through runtime, I was wondering how will I retrieve the number of rows affected after an update so I could prompt the user about it through VB.NET

What I'm actually doing is, after an update, if there are no other rows updated then the user can no longer click on the button

4 Answers 4

12

By using ExecuteNonQuery, it will returns no rows, any output parameters or return values mapped to parameters are populated with data.

For UPDATE, INSERT, and DELETE statements, the return value is the number of rows affected by the command.

EDIT:

You can prompt the User like

Dim RowsAffected as Integer = Command.ExecuteNonQuery()
MsgBox("The no.of rows effected by update query are " & RowsAffected.ToString)
Sign up to request clarification or add additional context in comments.

Comments

4

If you're using the SQLCommand object directly then a call to ExecuteNonQuery will return a count of rows affected:

Dim I as Integer= MyCommandObject.ExecuteNonQuery()

Hope this makes sense.

Comments

2

You can use SqlCommand for this:

Dim cmd As SqlCommand
Dim rows_Affected as Integer
rows_Affected = cmd.ExecuteNonQuery()

Comments

0

You can update your statements to return the rowcount value.

This should be helpful http://technet.microsoft.com/en-us/library/ms187316.aspx

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.