locked
To assign a value RRS feed

  • Question

  • Hi,

    We use such line to assign a value (that is of a textbox field) to a parameter of a command. How about assigning the value of a parameter to a textbox field?

    cmd.Parameters.Add("@par_name", SqlDbType.VarChar).Value = this.tb_user_nm.Text;


    Thanks & Best Regards, HuaMin Chen. In Hong Kong, China.
    Monday, December 29, 2008 6:27 AM

Answers

All replies

  • Hope it helps , 
     
    SqlParameter sq = new SqlParameter();

    textBox1.text  = sq.Value;

    ---- Don't forget to mark as answer if it solves the problem

    • Marked as answer by Guo Surfer Friday, January 2, 2009 6:01 AM
    • Unmarked as answer by Guo Surfer Friday, January 2, 2009 6:01 AM
    Monday, December 29, 2008 7:09 AM
  • Is it OK by this? 

    SqlParameter par_name1 = new SqlParameter();

    SqlParameter par_name2 = new SqlParameter();

    cmd = new SqlCommand("select "

    + "name1,"

    + "name2  into @par_name1,"

    + "@par_name2 from ... "
    ...


    Thanks & Best Regards, HuaMin Chen. In Hong Kong, China.
    Monday, December 29, 2008 9:00 AM
  • If you want output parameters go for this approach

    http://support.microsoft.com/default.aspx/kb/310130

    ---- Don't forget to mark as answer if it solves the problem
    • Proposed as answer by Akshay S Bhatnagar Tuesday, December 30, 2008 12:26 PM
    • Marked as answer by Guo Surfer Friday, January 2, 2009 6:00 AM
    Monday, December 29, 2008 9:53 AM
  • Hi HuaMin,

    We are marking Akshay's post as answer.
    If you still have problem, please feel free to unmark as the answer and change the issue type back to "Question" and follow up with more necessary information. If the issue is resolved, we will appreciate it if you can share the solution so that the answer can be found and used by other community members having similar questions.
    Thank you!

    Best regards,
    Guo
    Friday, January 2, 2009 6:02 AM