INSERT Label Control value into float column

liunx

Guest
How do you insert a value that a label control is holding into a float column in SQL Server? The insert does not execute when I try to insert the value from a label control into a float column.

ITEM_PRICE = float in SQL Server
lblPrice = is ID of Label Control
@ITEM_PRICE = parameter


SqlConnection con = new SqlConnection(....);
con.Open();
SqlCommand cmd = new SqlCommand("INSERT INTO TABLE (ITEM_PRICE) VALUES (@ITEM_PRICE)", con);
cmd.Parameters.Add("@ITEM_PRICE", lblPrice.Text);
cmd.ExecuteNonQuery();

What do I need to do to insert lblPrice value into a float column? I've tried converting and it raised errors.does this work?

cmd.Parameters.Add("@ITEM_PRICE", float.Parse(lblPrice.Text));You know what it was? I was taking a value from the label control that I converted to currency, which formatted the value with a ($). That's why I was not able to convert the value. What you posted is what I did and it worked. Thanks.
 
Back
Top