ASP.net中的语法错误 [英] Error in ASP.net in the syntax

查看:71
本文介绍了ASP.net中的语法错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下是使用sql server2008在数据库中添加数据的代码..但它无法正常工作..尝试与其他数据库相同但不在此工作..请帮助解决此问题

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

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");



错误:

关键字''order''附近的语法不正确。

描述:发生了未处理的异常在执行当前Web请求期间。请查看堆栈跟踪以获取有关错误及其在代码中的起源的更多信息。



异常详细信息: System.Data.SqlClient .SqlException:关键字''order''附近的语法不正确


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''

推荐答案

您的表名Order也是sql中的关键字,因此您必须编写它像这样。

Your table name "Order" is also a keyword in sql, so you will have to write it like this.
Insert into [order] ...


这篇关于ASP.net中的语法错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆