user3568422
user3568422

Reputation: 19

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: error

If I set the param to Int it still doesn't work.

Upvotes: 2

Views: 62

Answers (1)

Hassan
Hassan

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

Related Questions