2016-10-23 126 views
0

我想創建自己的網站,但我沒有太多經驗。我有問題將數據插入MS訪問。
我不太確定我的代碼有什麼問題,但它不起作用。 下面是我的代碼:
從asp.net插入數據到ms訪問數據庫

<%@ Page Language="VB" Debug="true" enableEventValidation="false" EnableViewStateMac="false" %> 
    <%@ Import Namespace="System.Data" %> 
    <%@ Import Namespace="System.Data.Oledb" %> 
    <%@ Import Namespace="System.IO" %> 
    <%@ Import Namespace="System.Net.Mail" %> 
    <%@ Import Namespace="System.Web" %> 




    <script runat="server"> 
    Dim LUsername As String 
    Dim dpic As Image 
    Dim MyCookieValue As String 
    Dim objConn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("\easytourtravelagency.mdb")) 
    Dim dr As OleDbDataReader 
    Dim ds1 As New DataSet() 
    Dim ds2 As New DataSet() 


    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) 

    Dim cmd124 As New OleDbCommand("INSERT INTO BookingDetails(CarID,Name,Innitial,EmailAddress,ContactNo,Gender,PickUpLocation,DateAndTime,NumberOfPassanger,SpecialRequest Values (@CarID, @Name, @EmailAddress, @ContactNo,@Gender,@PickUpLocation,@DateAndTime,@NumberOfPassanger,@SpecialRequest))", objConn) 
    cmd124.Parameters.AddWithValue("@CarID", CarID.Text) 
    cmd124.Parameters.AddWithValue("@Name", Name.Text) 
    cmd124.Parameters.AddWithValue("@EmailAddress", EmailAddress.Text) 
    cmd124.Parameters.AddWithValue("@ContactNo", ContactNo.Text) 
    cmd124.Parameters.AddWithValue("@Gender", Gender.Text) 
    cmd124.Parameters.AddWithValue("@PickUpLocation", PickUpLocation.Text) 
    cmd124.Parameters.AddWithValue("@DateAndTime", DateAndTime.Text) 
    cmd124.Parameters.AddWithValue("@NumberOfPassanger", NumberOfPassanger.Text) 
    cmd124.Parameters.AddWithValue("@SpecialRequest", SpecialRequest.Text) 
    cmd124.Connection.Open() 
    cmd124.ExecuteNonQuery() 
    cmd124.Connection.Close() 
End Sub 

回答

0

雖然我不知道ASP,你的SQL有語法錯誤,因爲它缺少INSERT INTO條款右括號上市柱後和有一個額外的括號VALUES從句:

INSERT INTO BookingDetails(CarID,Name,Innitial,EmailAddress, 
       ContactNo,Gender,PickUpLocation,DateAndTime, 
       NumberOfPassanger,SpecialRequest    -- MISSING PARERNTHESIS 
VALUES (@CarID, @Name, @EmailAddress, @ContactNo,@Gender,@PickUpLocation, 
     @DateAndTime,@NumberOfPassanger,@SpecialRequest)) -- EXTRA PARENTHESIS 
+0

嗨..非常感謝。它是由於我的SQL錯誤。謝謝。 – Eddy