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();
                }
}

Do you get an error? How do you know it's not working?

i don't get any error but the data is not updating when i try changing some value.

Are you running in debug mode? Are you using a file based database? Did you check the copy of the database that is made in the debug directory?

I already figured it out momerath anyway thank you for your help :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.