By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,041 Members | 1,793 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,041 IT Pros & Developers. It's quick & easy.

ExecuteNonQuery SQLCommand

P: n/a
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
Jul 19 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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
"Mark" <ma**@yahoo.comN0SPAM> wrote in message
news:bi**********@lust.ihug.co.nz...
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

Jul 19 '05 #2

P: n/a
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
Jul 19 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.