473,414 Members | 1,746 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

ExecuteNonQuery SQLCommand

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
2 7327
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Mark | last post by:
It appears that you can only retrieve an Output parameter from a SQL Server stored procedure when using the ExecuteNonQuery of the SqlCommand class, and cannot use the ExecuteReader() method. In...
10
by: Mike | last post by:
I know this sounds strange but I am at a loss. I am calling a simple funtion that opens a connection to a SQL Server 2000 database and executes an Insert Statement. private void...
1
by: Matthew Louden | last post by:
I just tried to create a simple ASP.NET application to add record to the SQL Server database. However, it has run time error on Line 88: objCommand.ExecuteNonQuery() Any ideas?? Please help!!...
0
by: Winshent | last post by:
I have some code which attempts to load the contents of a dataset into a sql server db. the code fills the dataadapter with the datset no prob, but fails on 'ExecuteNonQuery'. the function...
8
by: Stephen Costanzo | last post by:
We have an application that uses a SQLDataReader to cycle through a control table in the database and process records based upon that data. These records include things like the directory to poll...
2
by: Mark | last post by:
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...
22
by: b_r | last post by:
Hi, I'm trying to make a simple operation (insert into DB) in VB 2005 and SQL Server. The code is as follows: Dim sConnectionString As String = _ "Data...
2
by: TheSteph | last post by:
Hi I have a SQLCommand that do updates on a table. I have a loop where I set the parameters then I call ExecuteNonQuery. For . { . Set the SQLCommand's Params Values;
1
by: David | last post by:
Hello there, I am having problems with a stored procedure. When a use SqlCommand, SqlParameter and the ExecuteNonQuery method, i get this error: Server: Msg 170, Level 15, State 1, Line 1...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.