How to get the returned value from Stored Proc. ?

Discussion in 'ASP .Net' started by Jiggaz, Jul 8, 2004.

  1. Jiggaz

    Jiggaz Guest

    Hi,

    I have a stored procedure (ms sql 2005) which is return add
    the user in the table USERS. But the sp (stored proc) tests
    if a user with the desired nickname already exists. If
    exists, return -1 otherwise return 1 and execute the INSERT
    query!

    But, how to get the returned value from the stored
    procedure (called : CreateAccount) in ASP.NET ?

    My actual code :
    __________
    SqlCommand myCommand = new SqlCommand();
    String strCnx =
    ConfigurationSettings.ConnectionStrings["AppCnxStr"].ConnectionString.ToString();
    myCommand.Connection = new SqlConnection(strCnx);
    myCommand.Connection.Open();

    SqlParameter myNickname = new SqlParameter("@Nickname",
    SqlDbType.NVarChar, 30);
    myNickname.Value = boxLogin.Text;
    myCommand.Parameters.Add(myNickname);
    .... // same for all parameters.

    myCommand.ExecuteNonQuery();

    // here i want to get the value to make an if : if (value =
    1) COMPLETE REGISTRATION else GO BACK TO CHANGE NICKNAME.
    ________________________

    Regards.
    Jiggaz, Jul 8, 2004
    #1
    1. Advertising

  2. The .ExecuteScalarm method of the SqlCommand object is designed to return a
    single value... something like this

    int retVal = Convert.ToInt32(myCommand.ExecuteScalar());



    "Jiggaz" <> wrote in message
    news:294b701c46512$c5a5ca50$...
    Hi,

    I have a stored procedure (ms sql 2005) which is return add
    the user in the table USERS. But the sp (stored proc) tests
    if a user with the desired nickname already exists. If
    exists, return -1 otherwise return 1 and execute the INSERT
    query!

    But, how to get the returned value from the stored
    procedure (called : CreateAccount) in ASP.NET ?

    My actual code :
    __________
    SqlCommand myCommand = new SqlCommand();
    String strCnx =
    ConfigurationSettings.ConnectionStrings["AppCnxStr"].ConnectionString.ToStri
    ng();
    myCommand.Connection = new SqlConnection(strCnx);
    myCommand.Connection.Open();

    SqlParameter myNickname = new SqlParameter("@Nickname",
    SqlDbType.NVarChar, 30);
    myNickname.Value = boxLogin.Text;
    myCommand.Parameters.Add(myNickname);
    .... // same for all parameters.

    myCommand.ExecuteNonQuery();

    // here i want to get the value to make an if : if (value =
    1) COMPLETE REGISTRATION else GO BACK TO CHANGE NICKNAME.
    ________________________

    Regards.
    Robert Howells, Jul 8, 2004
    #2
    1. Advertising

  3. Jiggaz

    Todd Casey Guest

    You could also use the SqlParameter class and have the stored procedure
    return the value (ParameterDirection.Output). Just another option.

    Todd Casey
    Velocity West

    "Robert Howells" <> wrote in message
    news:...
    > The .ExecuteScalarm method of the SqlCommand object is designed to return
    > a
    > single value... something like this
    >
    > int retVal = Convert.ToInt32(myCommand.ExecuteScalar());
    >
    >
    >
    > "Jiggaz" <> wrote in message
    > news:294b701c46512$c5a5ca50$...
    > Hi,
    >
    > I have a stored procedure (ms sql 2005) which is return add
    > the user in the table USERS. But the sp (stored proc) tests
    > if a user with the desired nickname already exists. If
    > exists, return -1 otherwise return 1 and execute the INSERT
    > query!
    >
    > But, how to get the returned value from the stored
    > procedure (called : CreateAccount) in ASP.NET ?
    >
    > My actual code :
    > __________
    > SqlCommand myCommand = new SqlCommand();
    > String strCnx =
    > ConfigurationSettings.ConnectionStrings["AppCnxStr"].ConnectionString.ToStri
    > ng();
    > myCommand.Connection = new SqlConnection(strCnx);
    > myCommand.Connection.Open();
    >
    > SqlParameter myNickname = new SqlParameter("@Nickname",
    > SqlDbType.NVarChar, 30);
    > myNickname.Value = boxLogin.Text;
    > myCommand.Parameters.Add(myNickname);
    > ... // same for all parameters.
    >
    > myCommand.ExecuteNonQuery();
    >
    > // here i want to get the value to make an if : if (value =
    > 1) COMPLETE REGISTRATION else GO BACK TO CHANGE NICKNAME.
    > ________________________
    >
    > Regards.
    >
    >
    Todd Casey, Jul 8, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. David Lozzi

    Returning a value from a stored proc

    David Lozzi, Aug 10, 2004, in forum: ASP .Net
    Replies:
    6
    Views:
    575
    Edd Connolly
    Aug 11, 2004
  2. hansiman
    Replies:
    0
    Views:
    485
    hansiman
    Feb 5, 2005
  3. David Lozzi
    Replies:
    3
    Views:
    1,915
    David Lozzi
    Jun 1, 2005
  4. Cirene

    How get value from stored proc

    Cirene, May 11, 2008, in forum: ASP .Net
    Replies:
    2
    Views:
    870
    Cirene
    May 11, 2008
  5. CJM
    Replies:
    6
    Views:
    110
    Bob Barrows [MVP]
    Sep 6, 2005
Loading...

Share This Page