Reputation: 19
I'm using a stored procedure to update the rows in the column where the consignment number = @consignmentnumber.
Here is a screen of the code. I think I'm missing something but I can't work out I'm actually missing, can anyone help?
protected void BtnReceived_Click(object sender, EventArgs e)
{
IncrementStatusOfConsignment(sender);
}
private static void IncrementStatusOfConsignment(object sender)
{
var button = (Button) sender;
var gridviewrow = (GridViewRow) button.Parent.Parent;
var consignmentnumber = gridviewrow.Cells[3].Text;
using (var con = new SqlConnection(ConfigurationManager.ConnectionStrings["Test"].ConnectionString))
{
con.Open();
using (var cmd = new SqlCommand("Test", con))
{
cmd.CommandType = CommandType.StoredProcedure;
var sqlparam = cmd.Parameters.Add("@consignmentnumber", SqlDbType.VarChar);
sqlparam.Value = consignmentnumber;
cmd.ExecuteNonQuery();
}
}
}
Can anyone tell me where I've gone wrong or what I'm missing?
I constantly get this error:
If I set the param to Int it still doesn't work.
Upvotes: 2
Views: 62
Reputation: 5430
If you have declared column consignmentnumber
as Numeric(18, 0) then
var sqlparam = cmd.Parameters.Add("@consignmentnumber", SqlDbType.Decimal);
sqlparam.Value = consignmentnumber;
OR something like that:
var sqlparam = cmd.Parameters.Add("@consignmentnumber", SqlDbType.NVarChar, 18);
sqlparam.Value = consignmentnumber;
Upvotes: 1