ExecuteNonQuery SQLCommand

  • Thread starter Thread starter W.G.Ryan
  • Start date Start date
W

W.G.Ryan

Records Affectged doesn't show SELECT results. You could either use a
Count(*) in your query, or you could use dr = cmd.ExecuteReader() While
dr.Read()
i++;


It'd be cool if they had a feature to return rows affected in terms of
Select, but unless you use ADO.NET Disconnected (ie a DataAdapter, DataTable
etc) you can't do it.

Good Luck,

Bill
 
Hi, I have a sqlCommand object that I use to execute an SQL statement.

I thought I could use the ExecuteNonQuery to test for the number of rows
returned by the sql command but it does not seem to work

My code is below..

Dim sSQL As String = "SELECT Blah FROM Table WHERE BlahID = 5"

Dim oCOmmand As New SqlClient.SqlCommand(sSQL, openDatabase)

If oCOmmand.ExecuteNonQuery > 0 Then

' At least one row matches SQL statement

Else

' no rows match the sql statement

End If

Help appreciated as I thought the number ExecuteNonQuery returned the number
of rows affected by the SQL statement.

If I run the SQL command in query analyser I get at least one row returned.

Cheers
Mark
 
Cool, thanks for that! I realise that I could use the datareader object but
was hoping that I could just do it via the ExecuteNonQuery :)
Thanks again
Cheers
Mark
 
Back
Top