Re: Get Value

Tech-Archive recommends: Fix windows errors by optimizing your registry



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)

bbawa1@xxxxxxxxx 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.ConnectionStrings["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

.



Relevant Pages

  • Get Value
    ... I have following stored Procedure. ... SqlConnection objConn = new SqlConnection; ... SqlDataReader sqlDr; ... -- SET NOCOUNT ON added to prevent extra result sets from ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: fill dataset with stor pro
    ... The DataAdapter will fill a DataTable for each resultset ... It might be mandatory though to use SET NOCOUNT ... > I create one stored procedure have two select statement on it ...
    (microsoft.public.dotnet.framework.windowsforms)
  • Re: Getting the Stored Procedure ReturnValue and a recordset at the same time.
    ... value at the same time as getting a resultset. ... Dim ConnectionString As String ... > See my article on handling stored procedure parameters in SPs on my site. ...
    (microsoft.public.vb.database.ado)
  • Re: Adding date to parameter
    ... ClaimedDate does appear to have a properly formatted date. ... I am using the following stored procedure: ... -- SET NOCOUNT ON added to prevent extra result sets from ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: Stored Proc works everywhere except delphi - getting weirder
    ... I have no idea why SET NOCOUNT ON didn't help you. ... Here I quote a paragraph regarding my previous suggestion. ... an RDO Resultset object—it's related but not the same. ... put SET NOCOUNT ON in your stored procedure, in which case this packet ...
    (borland.public.delphi.database.ado)