I suppose that the last field HasBeenShipped
is a bit datatype in the database.
If this is the case then pass 0 (the numeric value) for it not 'false' (a string)
Moreover it is the parameter @p6
that contains the value for the field Total
and thus it is this parameter that should be converted to a number, while the parameter @p4
could be a string if the field Phone
is a NVarChar
com = new SqlCommand(@"INSERT INTO Orders
(OrderDate, Username, FirstName, LastName, Address, Phone, Total, HasBeenShipped)
VALUES(GetDate(), @p5, @p1, @p2, @p3, @p4, @p6, 0)", con2);
com.Parameters.AddWithValue("@p5", Label2.Text);
com.Parameters.AddWithValue("@p1", txtFname.Text);
com.Parameters.AddWithValue("@p2", TxtLname.Text);
com.Parameters.AddWithValue("@p3", TxtAdd.Text);
com.Parameters.AddWithValue("@p4", TxtNum.Text);
com.Parameters.AddWithValue("@p6", Convert.ToInt32(lblTotal.Text));
EDIT Following your comment below, if the lblTotal.Text
contains the currency symbol then you cannot convert directly to an integer with Convert.ToInt32, you should use decimal.TryParse
decimal totalValue
decimal.TryParse(lblTotal.Text, NumberStyles.Currency,
CultureInfo.CurrentCulture, out totalValue);
com.Parameters.AddWithValue("@p6", totalValue);