Problem sending values to stored procedure

Last post 02-26-2008 12:13 PM by murat.tufanoglu. 5 replies.

Sort Posts:

  • Problem sending values to stored procedure

    02-25-2008, 4:03 PM

    Hello 

    The project is running succesfuly when i wrote in textbox "20". But when i wrote there a float value like "20,1" or "20.1" the gridview doesn't bind. I checked the code with breakpoint. everything is okay. But i couldn't find the problem. This is my class about this subject.

    (a.proTocusWt get the all values which i entered to textbox.)

           public float proTocusWt;

            public DataTable datasearch()
            {
                SqlConnection connect = new SqlConnection(conString);
                connect.Open();
                SqlCommand command = new SqlCommand();
                command.CommandType = CommandType.StoredProcedure;
                command.CommandText = "fromProduct";
                command.Connection = connect;

                SqlParameter prm1 = new SqlParameter("@wt",SqlDbType.Float);

                prm1.Value = proTocusWt;


                command.Parameters.Add(prm1);

                SqlDataAdapter adap = new SqlDataAdapter(command);
                DataTable table = new DataTable();
                adap.Fill(table);
                return table;
            }

    And this is my Default.aspx.cs

        protected void Button1_Click(object sender, EventArgs e)
        {
            AddCustomer a = new AddCustomer(); //This is for creating a object...
            a.proTocusWt = Convert.ToSingle(TextBox1.Text);
            GridView1.DataSource = a.datasearch();
            GridView1.DataBind();
        }

     I think its happens because of the class. but i couldn't find it.

  • Re: Problem sending values to stored procedure

    02-25-2008, 7:52 PM
    Answer

    Use double, not single - most computers are optimized for the double type. Convert.ToDouble 

    Did you run your stored proc at the sql command line using 20.1 to see if it had any matches? 

    Please Mark As Answer posts that helped you.

    "If we learn from our mistakes, I should be brilliant by now."

  • Re: Problem sending values to stored procedure

    02-26-2008, 3:55 AM

    when i tried to Convert.ToDouble i got this error message

    "Cannot implicitly convert type 'double' to 'float'. An explicit conversion exists (are you missing a cast?)"

    the stored procedure works fine. I tried it with 20.1 Also it doesn't matter to using 20.1 or 20,1  

    a.proTocusWt was always 20.1 on code behind.

  • Re: Problem sending values to stored procedure

    02-26-2008, 8:56 AM
    Answer
    • Loading...
    • che3358
    • Joined on 09-25-2003, 10:23 AM
    • Cleveland, OH
    • Posts 845

    Check the data type of your a.proTocusWt. If you want to use a float or double, a.proTocusWt should be decimal or double.

  • Re: Problem sending values to stored procedure

    02-26-2008, 9:50 AM

     Agreed. I use Decimal for things that are numbers in the database. Otherwise you could lose precision (which is what that cast warning is about).

    Please Mark As Answer posts that helped you.

    "If we learn from our mistakes, I should be brilliant by now."

  • Re: Problem sending values to stored procedure

    02-26-2008, 12:13 PM

    yeahh the problem was that. thanks for the solution :) 

Page 1 of 1 (6 items)
Microsoft Communities
Page view counter