How to get the number of rows affected from SQL Server on VB.NET?

Basically I retrieve all the data in my program at runtime, I was wondering how I will get the number of rows affected after the update so that I can ask the user about it through VB.NET

What I'm actually doing, after updating, if there are no other updated lines, then the user can no longer click the button

+4
source share
4 answers

Using ExecuteNonQuery , it will not return rows; any output parameters or return values ​​associated with parameters are filled with data.

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

EDIT:

You can ask the user how

Dim RowsAffected as Integer = Command.ExecuteNonQuery() MsgBox("The no.of rows effected by update query are " & RowsAffected.ToString) 
+9
source

If you use the SQLCommand object directly, calling ExecuteNonQuery returns the number of rows affected:

 Dim I as Integer= MyCommandObject.ExecuteNonQuery() 

Hope this makes sense.

+2
source

You can use SqlCommand for this:

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

You can update your statements to return the rowcount value.

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

0
source

All Articles