473,396 Members | 2,151 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,396 software developers and data experts.

SQLHeper ExecuteNonQuery - returning values

Hi
I have a Stored Proc in SQL server, which creates a record key when a record
is created.

I want to return the value back to my code, once the record has been
created.

I am using SQLHelper (Data Application Blocks for SQLServer), and calling
the ExecuteNonQuery method in the SQLHelper class...

Does anyone have any sample code from their C# code, or T-SQL code to help??

Thanks
Paul
Nov 16 '05 #1
5 10936
Hi,

if you use ExecuteNonQuery, the way to return values is within output
parameters. In SQL documentation there are lots of about output parameters
however basically it is a proc parameter specified with OUTPUT keyword. For
example

CREATE PPROCEDURE myProc
....
@newid int OUTPUT
AS
....
/* set the value of the parameter somewhere here */

After the call to ExecuteNonQuery, this value is readable from the
SqlParameter given to the proc (which matches the @newid )

--
Teemu Keiski
ASP.NET MVP, Finland

"Paul Aspinall" <pa**@aspy.co.uk> wrote in message
news:0k*******************@fe3.news.blueyonder.co. uk...
Hi
I have a Stored Proc in SQL server, which creates a record key when a
record is created.

I want to return the value back to my code, once the record has been
created.

I am using SQLHelper (Data Application Blocks for SQLServer), and calling
the ExecuteNonQuery method in the SQLHelper class...

Does anyone have any sample code from their C# code, or T-SQL code to
help??

Thanks
Paul

Nov 16 '05 #2
Hi - Thanks for the reply.

I am familiar with output parameters from T-SQL, however, I cannot seem to
return values specifically using the SQL Application Blocks (SQLHelper).

Does SQLHelper support output params?

Thanks
"Teemu Keiski" <jo****@aspalliance.com> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
Hi,

if you use ExecuteNonQuery, the way to return values is within output
parameters. In SQL documentation there are lots of about output parameters
however basically it is a proc parameter specified with OUTPUT keyword.
For example

CREATE PPROCEDURE myProc
...
@newid int OUTPUT
AS
...
/* set the value of the parameter somewhere here */

After the call to ExecuteNonQuery, this value is readable from the
SqlParameter given to the proc (which matches the @newid )

--
Teemu Keiski
ASP.NET MVP, Finland

"Paul Aspinall" <pa**@aspy.co.uk> wrote in message
news:0k*******************@fe3.news.blueyonder.co. uk...
Hi
I have a Stored Proc in SQL server, which creates a record key when a
record is created.

I want to return the value back to my code, once the record has been
created.

I am using SQLHelper (Data Application Blocks for SQLServer), and calling
the ExecuteNonQuery method in the SQLHelper class...

Does anyone have any sample code from their C# code, or T-SQL code to
help??

Thanks
Paul


Nov 16 '05 #3
try using the ExecuteScalar instead this is design to return a single value
from a database call

HTH

Ollie Riches

"Paul Aspinall" <pa**@aspy.co.uk> wrote in message
news:WA*****************@fe2.news.blueyonder.co.uk ...
Hi - Thanks for the reply.

I am familiar with output parameters from T-SQL, however, I cannot seem to
return values specifically using the SQL Application Blocks (SQLHelper).

Does SQLHelper support output params?

Thanks
"Teemu Keiski" <jo****@aspalliance.com> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
Hi,

if you use ExecuteNonQuery, the way to return values is within output
parameters. In SQL documentation there are lots of about output parameters however basically it is a proc parameter specified with OUTPUT keyword.
For example

CREATE PPROCEDURE myProc
...
@newid int OUTPUT
AS
...
/* set the value of the parameter somewhere here */

After the call to ExecuteNonQuery, this value is readable from the
SqlParameter given to the proc (which matches the @newid )

--
Teemu Keiski
ASP.NET MVP, Finland

"Paul Aspinall" <pa**@aspy.co.uk> wrote in message
news:0k*******************@fe3.news.blueyonder.co. uk...
Hi
I have a Stored Proc in SQL server, which creates a record key when a
record is created.

I want to return the value back to my code, once the record has been
created.

I am using SQLHelper (Data Application Blocks for SQLServer), and calling the ExecuteNonQuery method in the SQLHelper class...

Does anyone have any sample code from their C# code, or T-SQL code to
help??

Thanks
Paul



Nov 16 '05 #4
Yes it does, if you declare parameter objects for it explictly. Have you
tried this?

--
Teemu Keiski
ASP.NET MVP, Finland

"Paul Aspinall" <pa**@aspy.co.uk> wrote in message
news:WA*****************@fe2.news.blueyonder.co.uk ...
Hi - Thanks for the reply.

I am familiar with output parameters from T-SQL, however, I cannot seem to
return values specifically using the SQL Application Blocks (SQLHelper).

Does SQLHelper support output params?

Thanks
"Teemu Keiski" <jo****@aspalliance.com> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
Hi,

if you use ExecuteNonQuery, the way to return values is within output
parameters. In SQL documentation there are lots of about output
parameters however basically it is a proc parameter specified with OUTPUT
keyword. For example

CREATE PPROCEDURE myProc
...
@newid int OUTPUT
AS
...
/* set the value of the parameter somewhere here */

After the call to ExecuteNonQuery, this value is readable from the
SqlParameter given to the proc (which matches the @newid )

--
Teemu Keiski
ASP.NET MVP, Finland

"Paul Aspinall" <pa**@aspy.co.uk> wrote in message
news:0k*******************@fe3.news.blueyonder.co. uk...
Hi
I have a Stored Proc in SQL server, which creates a record key when a
record is created.

I want to return the value back to my code, once the record has been
created.

I am using SQLHelper (Data Application Blocks for SQLServer), and
calling the ExecuteNonQuery method in the SQLHelper class...

Does anyone have any sample code from their C# code, or T-SQL code to
help??

Thanks
Paul



Nov 16 '05 #5
Paul,

For SqlHelper.ExecuteNonQuery you need to first define your output
parameters in .NET, call .ExecuteNonQuery (passing it the parameter object),
then reference the .Value of the parameter after your stored procedure
executes.

Let me know if you need code posted.

Paul
Nov 16 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

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...
11
by: Steven Blair | last post by:
Hi, I am using ODBC namespace and MySQl 4.1 and have hit this problem a number of times and had to do some nasty coding to get round the problem. I am convinced there is a easier way to do...
2
by: cesark | last post by:
I have calling a stored procedure that returns two values, and I want to catch these values and to store them into a variable. Here is a piece of my SP inside SQL Server that shows the returned...
1
by: Derek | last post by:
Another DGrid question... I can not access the values of a cell in a datagrid unless I make them visible. I do not want these fields displayed. I only want to use the values to run a stored...
4
by: scparker | last post by:
Hello, We have a stored procedure that does a basic insert of values. I am then able to retrieve the ID number created for this new record. We are currently using ASP.NET 2.0 and use N-Tier...
3
by: Manikandan | last post by:
Hi, I'm using executenonquery to check the existence of table in the database. I tried two methods of queries, everything return -1 even though table exists in database Code as below...
8
by: roundcrisis | last post by:
Hi all: I m trying to get the return value of a stored procedure with .... DbCommand command = connection.CreateCommand(); command.CommandText = "Exec some_SP"; command.CommandType =...
0
by: munya | last post by:
I am new in .asp I am trying to use dropdownlist to display values from the database and be able to query the database based on displayed values in a dropdownlist. the prob is when I select any...
4
by: rekhasc | last post by:
Front end: Asp.net Code: C# Backend:Msaccess i am doing project on loan, i have to insert the customer values to the database, its showing errors in cmd.executenonquery, public partial...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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:
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...
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
tracyyun
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...
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,...

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.