简体   繁体   中英

Can't get my Update to work

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.

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;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM