can anyone help me my sql update is not working.
cmd.Parameters.AddWithValue("MaterialSizeId", id);
the id on this parameter is already had a value.
Maybe the error is on sqltransaction. please help.
public void Update(string materialSize, string KgPermetre, string PricePerCut, string MaterialType, string BarColour, string PreferredLength, string datetime)
{
using (SqlConnection objcon = new SqlConnection(clsConnection.srConnectionString))
{
objcon.Open();
SqlTransaction ts = objcon.BeginTransaction();
try
{
using (SqlCommand cmd = new SqlCommand("ec_MaterialSize", objcon, ts) { CommandType = CommandType.StoredProcedure })
{
cmd.Parameters.AddWithValue("action", "Update");
cmd.Parameters.AddWithValue("MaterialSizeId", id);
cmd.Parameters.AddWithValue("MatSize", materialSize);
cmd.Parameters.AddWithValue("KgPerMetre", KgPermetre);
cmd.Parameters.AddWithValue("PricePerCut", PricePerCut);
cmd.Parameters.AddWithValue("MaterialType", MaterialType);
cmd.Parameters.AddWithValue("BarColour", BarColour);
cmd.Parameters.AddWithValue("PreferredLength", PreferredLength);
cmd.Parameters.AddWithValue("DateModified", datetime);
cmd.ExecuteNonQuery();
ts.Commit();
}
}
catch (DBConcurrencyException)
{
MessageBox.Show("The data has been altered by someone else\n" +
"while you have been working on it.");
ts.Rollback();
}
catch (Exception ex)
{
MessageBox.Show("Error : " + ex.Message);
ts.Rollback();
}
}