Tuesday, 15 January 2013

mysql - Getting a exception that says Parameter already defined -


Creating an application that is inserting or removing people from the database When I double click to delete a user, I get an exception that says: The parameter is already defined here is a small part of the code

  con.ConnectionString = (" server = local host; user id = root; password = ''; database = inventory_control ") Cmd.Connection = Thief con.Open () cmd.CommandText =" Employee where first_name = @fnametodelete "cmd.Parameters.Add (" @fnametodelete ", remove from MySqlDbType .string) .Value = stremployeeTodeleteName i Nttodelete = cmd.ExecuteNonQuery () con.Close () DataGridView2.Refresh () clearEmployee ()  

Screenshots show that you are reusing MySqlCommand . So you are adding parameters to every button click. Instead of creating a new command every time

  using the thief as the new MySqlConnection. ("Server = local host; userid = root; password = ''; database = inventory_control") using new cmd as MySqlCommand ("employee where first_name = @fnametodelete", thief) con.Open (cmd) .Parameters.Add ("@fnametodelete", MySqlDbType.String) .Value = stremployeeTodeleteName inttodelete = cmd.ExecuteNonQuery () Using the other end from the end  
< / Html>

No comments:

Post a Comment