ExecuteNonQuery doesn't return Count, what else to use
Posted on 2007-03-26
I thought I'd use this construct
Using wrkConnection As New SqlConnection(ConfigurationManager.ConnectionStrings(1).ToString)
Dim wrkSQLCmd As New SqlCommand(varSQLString, wrkConnection)
varRowCnt = wrkSQLCmd.ExecuteNonQuery()
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.