Click here to Skip to main content
15,888,527 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
SQL
string query = "Insert into survey(name,mobile,email,use,company,a1,a2,a3,a4,a5,a6)values('" + name.Text + "','" + mobile.Text + "','" + email.Text + "','"+Dropdownlist1.SelectedItem.Value+"','"+cmptxt.Text+"','" + a1.SelectedItem.Text + "','" + a2.SelectedItem.Text + "','" + a3.SelectedItem.Text + "','" + a4.SelectedItem.Text + "','" + a5.SelectedItem.Text + "','" + a6.Text + "')";
       MySqlCommand cmd = new MySqlCommand(query, con);



The error i got inserting the data in database is

MySql.Data.MySqlClient.MySqlException (0x80004005): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'use,company,a1,a2,a3,a4,a5,a6)values('eer','3432','jhjkahjkasd.com','Commercial'' at line 1 at MySql.Data.MySqlClient.MySqlStream.ReadPacket() at MySql.Data.MySqlClient.NativeDriver.GetResult(Int32& affectedRow, Int32& insertedId) at MySql.Data.MySqlClient.Driver.GetResult(Int32 statementId, Int32& affectedRows, Int32& insertedId) at MySql.Data.MySqlClient.Driver.NextResult(Int32 statementId, Boolean force) at MySql.Data.MySqlClient.MySqlDataReader.NextResult() at MySql.Data.MySqlClient.MySqlCommand.ExecuteReader(CommandBehavior behavior) at MySql.Data.MySqlClient.MySqlCommand.ExecuteReader() at MySql.Data.MySqlClient.MySqlCommand.ExecuteNonQuery() at _Default.Submit_Click(Object sender, EventArgs e) in e:\Important\Software Product Survey\Default.aspx.cs:line 25 
Posted

USE is a keyword, you need to put MySql quotes around it with a (`):
C#
string query = "Insert into survey(name,mobile,email,`use`,company ...
 
Share this answer
 
v2
Comments
My 5+. I was going to post this solution, but I found that you have already posted. :P :)

Thanks,
Tadit
Mehdi Gholam 1-Oct-13 2:24am    
Thanks Tadit!
Most Welcome. :)
Its should be easy to put the break point at the line MySqlCommand cmd = new MySqlCommand(query, con);. Copy the query variable contents and run directly on the database.
 
Share this answer
 
change your SQL as below and the code as below to accept parameters

string query ="Insert into survey(`name`,`mobile`,`email`,`use`,`company`,a1,a2,a3,a4,a5,a6)values(@name,@mobile,@email,@use,@company,@a1,@a2,@a3,@a4,@a5,@a6)";
MySqlCommand cmd = new MySqlCommand(query, con);
cmd.Parameters.AddWithValue("@name", name.Text);
// add all the parameter values
 
Share this answer
 
v3

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