Tech Off Thread

4 posts

Forum Read Only

This forum has been made read only by the site admins. No new threads or comments can be added.

How Can I Get String Value From My StoredProc by c#

Back to Forum: Tech Off
  • User profile image
    JuNK64

    SqlConnection conFriends = new SqlConnection("initial catalog=KAZANIM 2.0;data source=localhost;integrated security=sspi;packet size=4096");

    conFriends.Open();
    SqlCommand cmdInsert = new SqlCommand("JK_USRLOGIN", conFriends);

    cmdInsert.CommandType = CommandType.StoredProcedure;

    SqlParameter paramUSR = cmdInsert.Parameters.Add("@USR", SqlDbType.VarChar, 20);

    SqlParameter paramPWD = cmdInsert.Parameters.Add("@PWD", SqlDbType.VarChar, 20);

    SqlParameter paramAD = cmdInsert.Parameters.Add("@AD",

    SqlDbType
    .VarChar, 50);paramAD.Direction =ParameterDirection.ReturnValue;
    paramUSR.Value = textBox1.Text;

    paramPWD.Value = textBox2.Text;

    cmdInsert.ExecuteNonQuery();

    label1.Text = (string)paramAD.Value;

    /*
    HOW CAN I TAKE THE VALUE OF THE PARAM ????? AND INSERT TO LABEL1.TEXT?THE LINE ABOVE DOESN'T WORKS......  
    */

    conFriends.Close();

  • User profile image
    figuerres

    well in the sproc is that value set ??

    normally for simple returns is use ExecuteScalar()

    in the sproc i will have something like


    ..... code ....


    Select @foobar
    end


    and execute scalar gets @foobar automaticaly.

    KISS -- Keep it simple etc...

  • User profile image
    littleguru

    figuerres wrote:
    normally for simple returns is use ExecuteScalar()


    I second that. But I don't know if that works with stored procedures and output parameters.

  • User profile image
    figuerres

    littleguru wrote:
    
    figuerres wrote: normally for simple returns is use ExecuteScalar()


    I second that. But I don't know if that works with stored procedures and output parameters.


    after posting here I see the same thing is on another thread here...
    Grrrr.... makes it that much harder to give decent answers when the info is all over the place....

    ok that aside.

    if I need to return more than one data item what I do (may be wrong but it works) is this:

    Select @vara,@varb,@varc

    then do an execute reader

    if (Reader.Read())
    {
      a =  Reader[0]
    b = Reader[1]
    c = Reader[2]
    }

    and go from there...
    I may use .GetType() in some cases depends on the data and how sure I am of what I will get back.

Conversation locked

This conversation has been locked by the site admins. No new comments can be made.