codequest
asked on
ExecuteNonQuery doesn't return Count, what else to use
I thought I'd use this construct
Using wrkConnection As New SqlConnection(Configuratio nManager.C onnectionS trings(1). ToString)
Dim wrkSQLCmd As New SqlCommand(varSQLString, wrkConnection)
wrkSQLCmd.Connection.Open( )
varRowCnt = wrkSQLCmd.ExecuteNonQuery( )
End Using
to execute a Select Count or (simple Select query)...but I'm confused because MSDN says .ExecuteNonQuery() returns -1 except for Delete, update, insert.
What should I be using instead? I'd like to be able to pass the query string to this construct in a subroutine and have it return the count in a Byref...but mostly I've got to get something that will execute the string and return the count.
Any help with this would be appreciated.
Thanks!
Using wrkConnection As New SqlConnection(Configuratio
Dim wrkSQLCmd As New SqlCommand(varSQLString, wrkConnection)
wrkSQLCmd.Connection.Open(
varRowCnt = wrkSQLCmd.ExecuteNonQuery(
End Using
to execute a Select Count or (simple Select query)...but I'm confused because MSDN says .ExecuteNonQuery() returns -1 except for Delete, update, insert.
What should I be using instead? I'd like to be able to pass the query string to this construct in a subroutine and have it return the count in a Byref...but mostly I've got to get something that will execute the string and return the count.
Any help with this would be appreciated.
Thanks!
it Executes a Transact-SQL statement against the connection and returns the "number of rows affected"
i don't understand what is the prob actually.
if you want the row count then you can do executescaler that will return the first value..
eg.
your query:- select count(*) from emp
so 1st value:- row-count
ExecuteScalar will return only on value that is first column value of the first row in the executed query.
if you want the row count then you can do executescaler that will return the first value..
eg.
your query:- select count(*) from emp
so 1st value:- row-count
ExecuteScalar will return only on value that is first column value of the first row in the executed query.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for inputs. The "problem" is my acute newbie-itis in this area... :-)
'Preciate the pointers!
'Preciate the pointers!