I'm a database guy, so go easy on me here. :) How can I get the rowcount
of the affected rows of a SQL statement from a stored procedure call? I
know that "set nocount on" does not return the number of affected rows to
the client, so I would assume that "set nocount off" sends the number of
affected rows to the client, and therefore, is available programatically .
If so, how to get that rowcount?
Thanks,
Richard 4 23545
The SqlCommand.Exec uteNonQuery will return the rowcount for non queries. In
SELECT statements, well, just count how many rows you get :).
-mike
MVP
"Richard G" <ri*********@gt e.net> wrote in message
news:%2******** ********@TK2MSF TNGP11.phx.gbl. .. I'm a database guy, so go easy on me here. :) How can I get the rowcount of the affected rows of a SQL statement from a stored procedure call? I know that "set nocount on" does not return the number of affected rows to the client, so I would assume that "set nocount off" sends the number of affected rows to the client, and therefore, is available programatically . If so, how to get that rowcount?
Thanks, Richard
Mike-
int count = command.Execute NonQuery();
return ( ( count == -1 ) ? count : ((int)count / 2) );
Then why do I always have to halve the number of rows affected in order to
get an accurate result? Am I going about this wrong in some way? I
consistently get results that are double what my actual database tables
reflect, in both delete and bulk insert queries.
Thanks
------------------------------------------------------------
"Michael Giagnocavo [MVP]" <mg*******@Atre vido.net> wrote in message
news:eQ******** ******@TK2MSFTN GP12.phx.gbl... The SqlCommand.Exec uteNonQuery will return the rowcount for non queries.
In SELECT statements, well, just count how many rows you get :). -mike MVP
"Richard G" <ri*********@gt e.net> wrote in message news:%2******** ********@TK2MSF TNGP11.phx.gbl. .. I'm a database guy, so go easy on me here. :) How can I get the
rowcount of the affected rows of a SQL statement from a stored procedure call? I know that "set nocount on" does not return the number of affected rows
to the client, so I would assume that "set nocount off" sends the number of affected rows to the client, and therefore, is available
programatically . If so, how to get that rowcount?
Thanks, Richard
Do you have any triggers? One way would be to try using the SQL Query
analyser and see what's going on. I believe you can do a SELECT @@ROWCOUNT
after your query.
-mike
MVP
"m" <sk****@speakea sy.net> wrote in message
news:uf******** ************@sp eakeasy.net... Mike-
int count = command.Execute NonQuery();
return ( ( count == -1 ) ? count : ((int)count / 2) );
Then why do I always have to halve the number of rows affected in order to get an accurate result? Am I going about this wrong in some way? I consistently get results that are double what my actual database tables reflect, in both delete and bulk insert queries.
Thanks
------------------------------------------------------------
"Michael Giagnocavo [MVP]" <mg*******@Atre vido.net> wrote in message news:eQ******** ******@TK2MSFTN GP12.phx.gbl... The SqlCommand.Exec uteNonQuery will return the rowcount for non queries. In SELECT statements, well, just count how many rows you get :). -mike MVP
"Richard G" <ri*********@gt e.net> wrote in message news:%2******** ********@TK2MSF TNGP11.phx.gbl. .. I'm a database guy, so go easy on me here. :) How can I get the rowcount of the affected rows of a SQL statement from a stored procedure call?
I know that "set nocount on" does not return the number of affected rows to the client, so I would assume that "set nocount off" sends the number
of affected rows to the client, and therefore, is available programatically . If so, how to get that rowcount?
Thanks, Richard
I ran an identical bulk insert query in Query Analyzer and got the correct
number of rows import, 1520. However, with code, I always get 3040 for some
reason. Do you have any ideas why I am getting double the rows affected on
bulk inserts? This has happened on a dev box and our live boxes(we are
currently halving num rows affected in order to get accurate results from
the function, but now I am trying again because I don't like that band-aid
approach :) )
Thanks!
M
Query Analyzer:
BULK INSERT residential FROM
'\\workskibbs\c $\databases\ari zona\residentia lExport.txt' WITH
(FIELDTERMINATO R = '|', ROWTERMINATOR=' \n')
C# Code Chunk:
private int importData( string tableName )
{
string query = "BULK INSERT " + tableName + " FROM '" + OutputDirectory +
tableName + ".txt' WITH (FIELDTERMINATO R = '|', ROWTERMINATOR=' \n')";
SqlConnection connection;
connection = new SqlConnection(c onnectionString );
SqlCommand command = new SqlCommand( query, connection );
try
{
connection.Open ();
command.Command Timeout = 6000;
int count = command.Execute NonQuery();
Console.WriteLi ne( "Imported " + count.ToString( ) + " rows into the " +
tableName + " table..." );
return count;
}
catch( Exception yy )
{
new ErrorLog( yy.ToString() );
return -1;
}
finally
{
if( connection != null )
if( connection.Stat e == ConnectionState .Open )
connection.Clos e();
connection.Disp ose();
if( command != null )
command.Dispose ();
}
}
"Michael Giagnocavo [MVP]" <mg*******@Atre vido.net> wrote in message
news:%2******** ********@TK2MSF TNGP11.phx.gbl. .. Do you have any triggers? One way would be to try using the SQL Query analyser and see what's going on. I believe you can do a SELECT
@@ROWCOUNT after your query. -mike MVP
"m" <sk****@speakea sy.net> wrote in message news:uf******** ************@sp eakeasy.net... Mike-
int count = command.Execute NonQuery();
return ( ( count == -1 ) ? count : ((int)count / 2) );
Then why do I always have to halve the number of rows affected in order
to get an accurate result? Am I going about this wrong in some way? I consistently get results that are double what my actual database tables reflect, in both delete and bulk insert queries.
Thanks
------------------------------------------------------------
"Michael Giagnocavo [MVP]" <mg*******@Atre vido.net> wrote in message news:eQ******** ******@TK2MSFTN GP12.phx.gbl... The SqlCommand.Exec uteNonQuery will return the rowcount for non
queries. In SELECT statements, well, just count how many rows you get :). -mike MVP
"Richard G" <ri*********@gt e.net> wrote in message news:%2******** ********@TK2MSF TNGP11.phx.gbl. .. > I'm a database guy, so go easy on me here. :) How can I get the rowcount > of the affected rows of a SQL statement from a stored procedure
call? I > know that "set nocount on" does not return the number of affected
rows to > the client, so I would assume that "set nocount off" sends the
number of > affected rows to the client, and therefore, is available
programatically . > If so, how to get that rowcount? > > Thanks, > Richard > >
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Warren Wright |
last post by:
Hi group,
I have a select statement that if run against a 1 million record
database directly in query analyzer takes less than 1 second.
However, if I execute the select statement in a stored procedure
instead, calling the stored proc from query analyzer, then it takes
12-17 seconds.
Here is what I execute in Query Analyzer when bypassing the stored
procedure:
|
by: Cliff |
last post by:
here's my stored procedure:
CREATE PROCEDURE proc
@id varchar(50),@pswd varchar(20),@no_go int OUTPUT
AS
SET NOCOUNT ON
SELECT user_id FROM profile
WHERE user_id=\@id AND pswd=\@pswd
IF \@\@ROWCOUNT = 0
BEGIN
|
by: james cox via SQLMonster.com |
last post by:
I don't know if this is possible. However, what i am attempting to do is
using C#'s window forms. I open up an excell sheet stored in my windows
form. The excel sheet stores names of the stored procedures in that
database. I want to know if it's possible to click on that stored
procedure to open up a link to display the code of that stored procedure of
course in a read only mode.
any suggestions....
|
by: SandySears |
last post by:
I am trying to use a stored procedure to insert a record using VS 2005, VB
and SQL Server Express. The code runs without errors or exceptions, and
returns the new identifer in the output parameters. It returns my error text
message in another output parameter as "ok", which is the value that is set
in the stored procedure prior to doing the insert. It returns my var for
@@rowcount as 1. However, the record does not get into the table.
...
|
by: Siv |
last post by:
Hi,
I have a stored procedure that I want to execute and then wait in a loop
showing a timer whilst it completes and then carry on once I get
notification that it has completed. The main reason for this being to stop
the user thinking the application has frozen when in fact it is just waiting
for a long SP to complete. Another reason for doing it like this is that I
also have had a problem in the past where the SP takes longer than the...
| |
by: mch1ck3y |
last post by:
Hello there - hoping someone can offer some advice.
I am using SQL Server 2000 and want a stored procedure to execute 20 seconds after a particular field on a table is updated using a trigger on the table to be updated. Any ideas on how this would be achievable - any help would be greatly appreciated.
|
by: barmatt80 |
last post by:
I am stumped on the error reporting with sql server. I was told i
need to return @SQLCode(code showing if successful or not) and
@ErrMsg(and the message returned). I am clueless on this.
I wrote this procedure:
ALTER PROCEDURE .
@Emp_SSN int,
@Annual_Forward decimal(10,2),
|
by: stockton |
last post by:
I have written the following Stored Procedure in an attempt to update two tables in the same database reliably but unfortunately it is not too successful. I ocassionaly end up with only the BundlesIssued tables updated and nothing in TicketsIssued.
Please make suggestions on how I could make this stored procedure update both tables reliably.
ALTER PROCEDURE spIssueScannedTickets
@iEventID int,
@MemberNum nvarchar(12),
...
|
by: Jeganath |
last post by:
Hi,
I have written a Stored Procedure. I'm getting the error as below.
Maximum stored procedure, function, trigger, or view nesting level exceeded (limit 32).
Can any one give me a solution for this problem I have given the procedure below.
ALTER procedure .
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |