在执行aspx页面代码时,因调用vb文档的某方法,提示错误如标题所述“ERROR [42000] [Microsoft][ODBC SQL Server Driver][SQL Server]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: Microsoft.Data.Odbc.OdbcException: ERROR [42000] [Microsoft][ODBC SQL Server Driver][SQL Server]Incorrect syntax near the keyword 'Order'.Source Error: 
Line 97:         
Line 98:         Dim myOrder As Order = New Order()
Line 99:         myOrder.RecordOrder(myOrderDate, modelNumber, quantity, myOrderTotal, myShipDate)
Line 100:        
Line 101:    End Sub
 Source File: C:\Users\Anna\Documents\Visual Studio 2008\WebSites\CIATest\InventoryManagement.aspx    Line: 99 Stack Trace: 
[OdbcException: ERROR [42000] [Microsoft][ODBC SQL Server Driver][SQL Server]Incorrect syntax near the keyword 'Order'.]
   Microsoft.Data.Odbc.OdbcConnection.HandleError(IntPtr hHandle, SQL_HANDLE hType, RETCODE retcode) +27
   Microsoft.Data.Odbc.OdbcCommand.ExecuteReaderObject(CommandBehavior behavior, String method) +828
   Microsoft.Data.Odbc.OdbcCommand.ExecuteNonQuery() +72
   Order.RecordOrder(DateTime orderDate, String modelNumber, Int32 quantity, Decimal orderTotal, DateTime shipDate) +299
   ASP.InventoryManagement_aspx.PlaceOrder_Click(Object sender, EventArgs e) in C:\Users\Anna\Documents\Visual Studio 2008\WebSites\CIATest\InventoryManagement.aspx:99
   System.Web.UI.WebControls.Button.OnClick(EventArgs e) +83
   System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +57
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +18
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
   System.Web.UI.Page.ProcessRequestMain() +1292 
--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:1.1.4322.2407; ASP.NET Version:1.1.4322.2407 我的aspx页面出错段代码如下:
 Protected Sub PlaceOrder_Click(ByVal sender As Object, ByVal e As System.EventArgs)   
        Dim myProductDB As ProductDB = New ProductDB()
        Dim myProductID As Integer = Integer.Parse(ProductDrop2.SelectedValue)
        
        Dim userName As String = "[email protected]"
        Dim password As String = "huangzhao"
        Dim modelNumber As String = myProductDB.GetModelNumber(myProductID)
        Dim quantity As Integer = Integer.Parse(TBQuantity.Text)
        
        'calling the web service from IBuySpy
        Dim myOrderItem As IbuyspyTest.OrderItemByModelNumber = New IbuyspyTest.OrderItemByModelNumber()
        myOrderItem.Url = "http://localhost:81/OrderItemByModelNumber.asmx"
        
        Dim myOrderID As Integer = myOrderItem.OrderItem(userName, password, modelNumber, quantity)
        Title2.Text = "Your Order is successful! Please record your Order ID " & myOrderID.ToString()
        
        Dim myOrderDetail2 As IbuySpyTest.OrderDetails = myOrderItem.CheckStatus(userName, password, myOrderID)
        
        Dim myOrderDate As DateTime = myOrderDetail2.OrderDate
        Dim myShipDate As DateTime = myOrderDetail2.ShipDate
        Dim myOrderTotal As Decimal = myOrderDetail2.OrderTotal
        
        Dim myOrder As Order = New Order()
        myOrder.RecordOrder(myOrderDate, modelNumber, quantity, myOrderTotal, myShipDate)
        
    End Sub调用的vb文档的recordOrder()方法代码如下Public Class Order
    Public Function RecordOrder(ByVal orderDate As DateTime, ByVal modelNumber As String, ByVal quantity As Integer, ByVal orderTotal As Decimal, ByVal shipDate As DateTime)
        Dim SQL As String = "Insert Into Order(OrderDate, ModelNumber, Quantity, OrderTotal, ShipDate) Values ({0}, '{1}',{2},{3},{4})"        Dim SQLstr As String = String.Format(SQL, orderDate, modelNumber, quantity, orderTotal, shipDate)        Dim connstr As String = ConfigurationSettings.AppSettings("ConnectionString")        Dim myConnection As OdbcConnection = New OdbcConnection(connstr)
        Dim myCommand As OdbcCommand = New OdbcCommand(SQLstr, myConnection)        myConnection.open()
        myCommand.ExecuteNonQuery()
        myConnection.Close()    End Function
End Class请各位高手务必支招!!
小妹不胜感激!

解决方案 »

  1.   

    Incorrect syntax near the keyword 'Order'不正确的语法附近的关键字'订单' Dim SQL As String = "Insert Into Order(OrderDate, ModelNumber, Quantity, OrderTotal, ShipDate) Values ({0}, '{1}',{2},{3},{4})" 
    把order加个[]就可以了       
     
    Dim SQL As String = "Insert Into [Order](OrderDate, ModelNumber, Quantity, OrderTotal, ShipDate) Values ({0}, '{1}',{2},{3},{4})"  
      

  2.   

    错误提示很清楚'Order'是 keyword,你的表名用的关键字,要区分就把表名换为 [Order]
      

  3.   

    太感谢了~改过了 但是提示OrderTotal和ShipDate附近有错
    OrderTotal在数据库里是decimal, shipDate是datetime
    这两个的占位符的写法是不是也不对~麻烦再给我讲一下好吧~~
    谢谢 !