Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / June 2007

Tip: Looking for answers? Try searching our database.

Get Value

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
bbawa1@yahoo.com - 19 Jun 2007 21:25 GMT
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
sloan - 19 Jun 2007 22:10 GMT
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.

> 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["twcsanConnectio
nString"].ConnectionString;
>         SqlConnection objConn = new SqlConnection(constr);
>         string sqlstmt = "usp_Update_tbtickets";
[quoted text clipped - 31 lines]
> Return @id
> END
bruce barker - 20 Jun 2007 00:43 GMT
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)

> Hi,
>
[quoted text clipped - 38 lines]
>     Return @id
> END

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.