Click here to Skip to main content
15,878,231 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Im sorry if you have seen this question a thousand times, But ive googled this and still couldnt find a solution. I googled and changed my code a bit but it still doesnt fix my code.

So,i want insert data into my Mysql table But it kept giving me errors, the lastest of which is "Only MySqlParamaters objects may be stored",

Here is my Code:

MySqlConnection con = new MySqlConnection(ConfigurationManager.ConnectionStrings["MySql"].ConnectionString);

string com = "INSERT INTO Users(Name, Surname, Pass, Email, Type)
VALUES(@Name,@Surname,@Password,@Emailaddr, @type)";

MySqlCommand Com = new MySqlCommand(com, con);

Com.CommandType = CommandType.Text;
Com.Parameters.Add(new MySqlParameter("?Name", MySqlDbType.Text).Value = txtfname.Text);
Com.Parameters.Add(new MySqlParameter("?Surname", MySqlDbType.Text).Value = txtlname.Text);
Com.Parameters.Add(new MySqlParameter("?Password", MySqlDbType.Text).Value = txtpass11.Text);
Com.Parameters.Add(new MySqlParameter("?Emailaddr", MySqlDbType.Text).Value = txtemail.Text);
Com.Parameters.Add(new MySqlParameter("?type", MySqlDbType.Text).Value = "Patient");

con.Open();
Com.ExecuteNonQuery();

con.Close();
Posted

1 solution

Use '@' instead of '?'. As the Parameters name should be the Same as that of arguments.
 
Share this answer
 
Comments
Raidzen10 27-Mar-12 10:21am    
Same exception occurs.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900