0

i watched a course and the teacher write this code and its worked for him but shows me this error.. my CODE

private void button2_Click(object sender, EventArgs e){
 con.Open();
 SqlCommand cmd = new SqlCommand("update Admin set 
 username=@username.password=@password.Fullname=@Fullname")
 cmd.Parameters.AddWithValue("@username", textuser.Text);
 cmd.Parameters.AddWithValue("@password", textpassword.Text);
 cmd.Parameters.AddWithValue("@Fullname", textFullname.Text);
 cmd.Parameters.AddWithValue("@id", id);
 cmd.ExecuteNonQuery(); // Error In This Line...
 con.Close();
 MessageBox.Show("DELETED");
 upload_data_into_GridView_from_database();
}
GMB
  • 216,147
  • 25
  • 84
  • 135
Rawand
  • 41
  • 6

2 Answers2

4

The dots in the query should be commas instead. And as far as your code is concerned, the query seems to be missing a where clause to filter on id (or the-like):

I would suggest:

update admin
set username = @username, password = @password, Fullname = @Fullname
where id = @id
GMB
  • 216,147
  • 25
  • 84
  • 135
1

you are missing an e, in ExecuteNonQuery:

cmd.ExecuteNonQuery();

Also instead of a . you need a comma (,) on your update query:

apomene
  • 14,282
  • 9
  • 46
  • 72