Click here to Skip to main content
15,890,438 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:

Incorrect syntax near the keyword 'table'.



protected void Button2_Click(object sender, EventArgs e)
{
// string query;
string str = "Data Source=HIMANSHU-PC;Initial Catalog=new1;Integrated Security=True";
SqlConnection con = new SqlConnection(str);
con.Open();
string query = "insert into table dbinfo values('" + TextBox1.Text + "','" + TextBox2.Text + "')";
SqlCommand cmd = new SqlCommand(query,con);
cmd.ExecuteNonQuery();
con.Close();


}
Posted
Comments
[no name] 13-Oct-14 8:17am    
http://www.w3schools.com/sql/sql_insert.asp
Then you need to use parameterized queries.

Do not use queries in code behind! Have you ever heard about SQL Injection?
Please, see my past answers[^].
 
Share this answer
 
Your code is vulnerable to SQL injection
 
Share this answer
 
Google it first,You need some more practices

No need to use"table" in your query,

Try this,

string query = insert into dbinfo values('" + TextBox1.Text + "','" + TextBox2.Text + "')";
 
Share this answer
 
v2
Comments
Member 11132163 13-Oct-14 8:45am    
Thx!!!
Richard Deeming 13-Oct-14 9:13am    
You've copied the SQL Injection[^] vulnerability from the question's code.

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