update statement not updating data in db

Viewed 31

I am trying to update the data using an UPDATE statement. I am not getting any run time errors. However, no data is being updated in the database. Looks like something is missing in the 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;
}   
0 Answers
Related