update statement not updating data in db

Issue

This Content is from Stack Overflow. Question asked by Mohd Sameer

net Genius,

I am trying to update the data using “UPDATE” statement. I am not getting any run time error. However, no data is being updated in the database. Looks like something is missing in where clause.

        try
        {
            using (MySqlConnection con = new MySqlConnection(ConfigurationManager.AppSettings["RL_InventoryConnection"])) /*"*/
            {
                if (con.State == ConnectionState.Closed)
                    con.Open();

                MySqlCommand cmd = new MySqlCommand("UPDATE vendormaster SET vendor_name = @vendor_name, vendor_contact_Name1 = @vendor_contact_Name1, vendor_contact_phone1 = @vendor_contact_phone1, vendor_contact_email1 = @vendor_contact_email1, vendor_contact_Name2 = @vendor_contact_Name2, vendor_contact_phone2 = @vendor_contact_phone2, vendor_contact_email2 = @vendor_contact_email2, vendor_pan = @vendor_pan, vendor_gst = @vendor_gst, vendor_address = @vendor_address, vendor_pincode = @vendor_pincode, vendor_city = @vendor_city, vendor_country = @vendor_country WHERE vendor_name like '%@vendor_name%'; ", con);
                cmd.Parameters.AddWithValue("@vendor_name", getvendorname);
                cmd.Parameters.AddWithValue("@vendor_contact_Name1", getcontactperson1);
                cmd.Parameters.AddWithValue("@vendor_contact_phone1", getcontactphone1);
                cmd.Parameters.AddWithValue("@vendor_contact_email1", getcontactemail1);
                cmd.Parameters.AddWithValue("@vendor_contact_Name2", getcontactperson2);
                cmd.Parameters.AddWithValue("@vendor_contact_phone2", getcontactphone2);
                cmd.Parameters.AddWithValue("@vendor_contact_email2", getpersonemail2);
                cmd.Parameters.AddWithValue("@vendor_pan", getvendorPan);
                cmd.Parameters.AddWithValue("@vendor_gst", getvendorgst);
                cmd.Parameters.AddWithValue("@vendor_address", getvendoraddress);
                cmd.Parameters.AddWithValue("@vendor_pincode", getpincode);
                cmd.Parameters.AddWithValue("@vendor_city", getcity);
                cmd.Parameters.AddWithValue("@vendor_country", getcountry);

                cmd.ExecuteNonQuery();
            }


        }

        catch (Exception ex)
        { 
            throw ex;
        }   


     
       



Solution

This question is not yet answered, be the first one who answer using the comment. Later the confirmed answer will be published as the solution.

This Question and Answer are collected from stackoverflow and tested by JTuto community, is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.

people found this article helpful. What about you?