Click here to Skip to main content
15,911,030 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Following is the code to add data in database using sql server2008.. but it is not working.. tried the same with other database but not working in this.. please help to solve this problem
C#
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["RegConnectionString"].ConnectionString);
        con.Open();
        string insCmd = "Insert into order(BookName,Author,Category,Publisher,Edition,Price,Quantity) values(@BookName,@Author,@Category,@Publisher,@Edition,@Price,@Quantity)";
        SqlCommand insertUser = new SqlCommand(insCmd, con);
        insertUser.Parameters.AddWithValue("@BookName", TextBox1.Text);
        insertUser.Parameters.AddWithValue("@Author", TextBox2.Text);
        insertUser.Parameters.AddWithValue("@Category", DropDownList1.SelectedItem.ToString());
        insertUser.Parameters.AddWithValue("@Publisher", TextBox3.Text);
        insertUser.Parameters.AddWithValue("@Edition", TextBox4.Text);
        insertUser.Parameters.AddWithValue("@Price", TextBox5.Text);
        insertUser.Parameters.AddWithValue("@Quantity", TextBox6.Text);     
      
   insertUser.ExecuteNonQuery();
   con.Close();
   Response.Redirect("bookordered.aspx");

Error:
Incorrect syntax near the keyword 'order'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.SqlClient.SqlException: Incorrect syntax near the keyword 'order'
Posted
Updated 26-Feb-13 6:38am
v3

1 solution

Your table name "Order" is also a keyword in sql, so you will have to write it like this.
SQL
Insert into [order] ...
 
Share this answer
 
Comments
Member 8780842 26-Feb-13 12:47pm    
Thank u :)
got it :) :)
fjdiewornncalwe 26-Feb-13 15:04pm    
You are welcome.
Sergey Alexandrovich Kryukov 26-Feb-13 14:01pm    
Caught it, a 5.
—SA
fjdiewornncalwe 26-Feb-13 15:04pm    
Thanks Sergey.

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