none
command Parameter Problem RRS feed

  • Question

  • hi.. Can any body helps me to solve this problem . I have one Stored Procedure


    ALTER PROCEDURE GetStd_Details ( @sno int, @sname varchar(50) output, @fee money output )
    as
    begin
    Select sname,fee from std where sno=@sno
    End


    And I have taken three textBoxs and one button in windows Forms I have wrote this code under button click


    SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionString["Constr"].ConnectionString);
    SqlCommand cmd = new SqlCommand("GetStd_Details", con);
    cmd.CommandType = CommandType.StoredProcedure;
    cmd.Parameters.AddWithValue("@sno", textBox1.Text);
    cmd.Parameters.Add("@sname", SqlDbType.VarChar).Direction = ParameterDirection.Output;
    cmd.Parameters["@sname"].Size = 50;
    cmd.Parameters.Add("@fee", SqlDbType.Money).Direction = ParameterDirection.Output;
    con.Open();
    cmd.ExecuteNonQuery();
    textBox2.Text = cmd.Parameters["@sname"].Value.ToString();
    textBox3.Text = cmd.Parameters["@fee"].Value.ToString();


    The problem is that when i m entering a valid sid which is present in my database table and clicking on button
    then i m not getting sname,and fee....(Result is Empty textBoxs)

    no error is comming also....
    thanks in Advanced

    • Changed type VikasGupta Tuesday, October 12, 2010 3:22 PM
    • Changed type VikasGupta Tuesday, October 12, 2010 4:28 PM
    Tuesday, October 12, 2010 3:17 PM

Answers

  • The reason is simple - you are not assigning any values to @sname and @fee parameters inside of your stored procedure. Stored procedure just executes SQL statement and you can receive that result using DataReader or DataAdapter, but there is no code that actually assigns values to parameters.


    Val Mazur (MVP) http://www.xporttools.net
    Tuesday, October 12, 2010 5:40 PM
    Moderator

All replies