protected void Update_Click(object sender, EventArgs e)
{
//string query = "update [user]" ;
//query += "set name ='" + "@name" + "',";
// query += "phone ='" +"@phone" +"'";
// query += "where (id = `@id`)";
string que = "UPDATE [user] SET ";
que += "[name] =@name, [phone]=@phone1 WHERE (id = 10)";
SqlConnection conn = new SqlConnection(ConnectionString);
try
{
SqlCommand cmd = new SqlCommand(que, conn);
conn.Open();
string name = Name.Text;
cmd.Parameters.AddWithValue("@id", int.Parse (Id.Text));
cmd.Parameters.AddWithValue("@name1", name);
cmd.Parameters.AddWithValue("@phone1", Phone.Text);
//cmd.Parameters.
msg.Text = que;
//cmd.ExecuteNonQuery();
}
catch(Exception err){
msg.Text = err.Message;
//msg.Text += query;
}
}
here the parameters.addwith value does not updating the values of parameter @name and @phone, when i do the same method for insert it work fine .what is the wrong in my code please help. i try to debug the code and i found that
cmd.Parameters.AddWithValue("@name1", name); and cmd.Parameters.AddWithValue("@phone1", Phone.Text); not working proper i mean it not replace the value of@name1 insted ,it update database name field with '@name1'