473,387 Members | 1,365 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,387 software developers and data experts.

Get Value

Hi,

I have following stored Procedure. I am writng following ado.net code
to get return value from stored procedure but it doesn't work.

String constr =
System.Configuration.ConfigurationManager.Connecti onStrings["twcsanConnectionString"].ConnectionString;
SqlConnection objConn = new SqlConnection(constr);
string sqlstmt = "usp_Update_tbtickets";
SqlCommand objCmd = new SqlCommand(sqlstmt, objConn);
objConn.Open();

//objCmd.ExecuteNonQuery();
SqlDataReader sqlDr;
sqlDr = objCmd.ExecuteReader();
while (sqlDr.Read())
{
Session["TCKid"] = Convert.ToInt32(sqlDr.GetValue(0));
}
sqlDr.Close();
objConn.Close();

CREATE PROCEDURE [twcsan].[usp_Update_tbtickets]
-- Add the parameters for the stored procedure here
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
DECLARE @id INT

SET NOCOUNT ON;
SET @id = (select top 1 ticketid from tbtickets where TcktStatusid
= 1)

update tbtickets
Set tcktopened = GetDate(), TcktAudited = GetDate(),TcktStatusid =
2
where ticketid = @id and TcktStatusid = 1

Return @id
END

Jun 19 '07 #1
2 1716

You want ExecuteScalar I believe.

Or you can declare an output parameter , and get it.

ExecuteReader is for a resultSET. (Select a, b, c from MyTable) , not a
single item.

<bb****@yahoo.comwrote in message
news:11**********************@e9g2000prf.googlegro ups.com...
Hi,

I have following stored Procedure. I am writng following ado.net code
to get return value from stored procedure but it doesn't work.

String constr =
System.Configuration.ConfigurationManager.Connecti onStrings["twcsanConnectio
nString"].ConnectionString;
SqlConnection objConn = new SqlConnection(constr);
string sqlstmt = "usp_Update_tbtickets";
SqlCommand objCmd = new SqlCommand(sqlstmt, objConn);
objConn.Open();

//objCmd.ExecuteNonQuery();
SqlDataReader sqlDr;
sqlDr = objCmd.ExecuteReader();
while (sqlDr.Read())
{
Session["TCKid"] = Convert.ToInt32(sqlDr.GetValue(0));
}
sqlDr.Close();
objConn.Close();

CREATE PROCEDURE [twcsan].[usp_Update_tbtickets]
-- Add the parameters for the stored procedure here
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
DECLARE @id INT

SET NOCOUNT ON;
SET @id = (select top 1 ticketid from tbtickets where TcktStatusid
= 1)

update tbtickets
Set tcktopened = GetDate(), TcktAudited = GetDate(),TcktStatusid =
2
where ticketid = @id and TcktStatusid = 1

Return @id
END

Jun 19 '07 #2
you want the proc return value, while you are trying to fetch the first
column of the resultset. as your resultset is empty there is nothing to
read, so you should use ExecuteNonQuery

add a parameter of ParameterDirection ReturnValue to the SqlCommand
parameter list, then you can read its value after calling ExecuteNonQuery.

-- bruce (sqlwork.com)

bb****@yahoo.com wrote:
Hi,

I have following stored Procedure. I am writng following ado.net code
to get return value from stored procedure but it doesn't work.

String constr =
System.Configuration.ConfigurationManager.Connecti onStrings["twcsanConnectionString"].ConnectionString;
SqlConnection objConn = new SqlConnection(constr);
string sqlstmt = "usp_Update_tbtickets";
SqlCommand objCmd = new SqlCommand(sqlstmt, objConn);
objConn.Open();

//objCmd.ExecuteNonQuery();
SqlDataReader sqlDr;
sqlDr = objCmd.ExecuteReader();
while (sqlDr.Read())
{
Session["TCKid"] = Convert.ToInt32(sqlDr.GetValue(0));
}
sqlDr.Close();
objConn.Close();

CREATE PROCEDURE [twcsan].[usp_Update_tbtickets]
-- Add the parameters for the stored procedure here
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
DECLARE @id INT

SET NOCOUNT ON;
SET @id = (select top 1 ticketid from tbtickets where TcktStatusid
= 1)

update tbtickets
Set tcktopened = GetDate(), TcktAudited = GetDate(),TcktStatusid =
2
where ticketid = @id and TcktStatusid = 1

Return @id
END
Jun 19 '07 #3

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

Similar topics

1
by: G Kannan | last post by:
Hey all! I have written a perl script to retrieve information from a HTML Form and insert the data into an Oracle database table. I am gettting the the following error message: "Use of...
3
by: otto | last post by:
i need to read a variable in a javascript and translate it to a form in html the javascript variable is: <SCRIPT LANGUAGE='JavaScript'>RF2N('Total');</script> and i need to put that...
3
by: Eric Chang | last post by:
I was working on this simple form with radio boxes. And when I click on one of the radio box, it tell me the value is "undefined" Why is that ? I did defined the value of each radio box: ...
16
by: cwizard | last post by:
I'm calling on a function from within this form, and there are values set but every time it gets called I get slammed with a run time error... document.frmKitAmount.txtTotalKitValue is null or not...
4
by: dmiller23462 | last post by:
So here's my problem.....I need to set up different email distributions based on which option in the following Select form has been chosen....For instance if "Putaway" is chosen it needs to email...
7
by: matthew_carver | last post by:
Hello, I have an ASP page that loops through a SQL Server 2000 table, then downloads an Excel sheet the users can save, etc. Works fine, except, I see that in one particular "comments" field the...
13
by: dbuchanan | last post by:
Hello, Here is the error message; ---------------------------- Exception Message: ForeignKeyConstraint Lkp_tbl040Cmpt_lkp302SensorType requires the child key values (5) to exist in the...
0
by: tania | last post by:
i have this table in my database: CREATE TABLE FILM( F_ID INT(5) NOT NULL AUTO_INCREMENT, F_TITLE VARCHAR(40) NOT NULL, DIRECTOR_FNAME VARCHAR(20) NOT NULL, DIRECTOR_LNAME VARCHAR(20) NOT NULL,...
1
by: cbellew | last post by:
Hi guys, I have a problem with an option group and a two corresponding text boxes. When the user chooses an option value i want the text boxes to populate with text dependent on the choice made....
275
by: Astley Le Jasper | last post by:
Sorry for the numpty question ... How do you find the reference name of an object? So if i have this bob = modulename.objectname() how do i find that the name is 'bob'
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
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
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,...

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.