2012-08-01 17 views
1

我的probelm是在da.Update(dt)。我收到OleDbException未處理。 INSERT INTO語句中的語法錯誤。奇怪的是它之前運行過,當時我只保存了10個項目,現在它完全不能運行。感謝您的幫助。vb.net ...我在做什麼錯誤的工作訪問

Dim dt As New DataTable 
    Dim ds As New DataSet 

    con.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source= C:\MyComplete.accdb;Persist Security Info=False;" 

    con.Open() 
    MsgBox("here") 
    ds.Tables.Add(dt) 

    Dim da As New OleDbDataAdapter 

    da = New OleDbDataAdapter("SELECT * FROM DealerReview", con) 

    da.Fill(dt) 


    Dim newRow As DataRow = dt.NewRow 

    newRow.Item(1) = User 
    newRow.Item(2) = Associate 
    newRow.Item(3) = "1" 
    newRow.Item(4) = Time 
    newRow.Item(5) = Hold 
    newRow.Item(6) = GreetingR 
    newRow.Item(7) = GreetingA 
    newRow.Item(8) = GreetingO 
    newRow.Item(9) = GreetingTs 
    newRow.Item(10) = GreetingG 
    newRow.Item(11) = holdUpdate 
    newRow.Item(12) = LookupSize 
    newRow.Item(13) = DlyD 
    newRow.Item(14) = SiPrice 
    newRow.Item(15) = SiDoorPrice 
    newRow.Item(16) = TBrand 
    newRow.Item(17) = TModel 
    newRow.Item(18) = SeveralChoices 
    newRow.Item(19) = Financing 
    newRow.Item(20) = Benefits 
    newRow.Item(21) = Apt 
    newRow.Item(22) = ITime 
    newRow.Item(23) = AssociateScore 
    newRow.Item(24) = hms 
    newRow.Item(25) = ymd 
    newRow.Item(26) = ElapsedTime 


    dt.Rows.Add(newRow) 
    Dim cb As New OleDbCommandBuilder(da) 
    cb.GetInsertCommand() 
    da.Update(dt) 
    MsgBox("Saved") 
    con.Close() 
+0

+1:因爲,一如既往,在你需要時尋求幫助是一件好事。 – RBarryYoung 2012-08-01 14:16:05

回答

0

這是當你的項目的數量和/或數據類型的不匹配,你正在寫表中的列定義是你的錯誤。還有其他可能性,但是由於您提到您添加了更多項目,並且您沒有向我們展示表格定義,這似乎是最有可能的。

您不能只添加更多項目(列)到數據庫命令,他們必須匹配您正在讀/寫的表列。

+0

好吧,訪問中的列將需要與正在保存的變量相同的名稱? 我對此很新,所以只是有點失落。就目前而言,這是我擁有的關於我的數據庫的所有代碼 – Jbailey01 2012-08-01 14:07:57

+0

如果您使用它們的名稱,那麼是的。但是您發佈的代碼只是使用它們的列號:Item(1),Item(2)等。您需要進入Access數據庫並查看DealerReview表的定義。這應該讓事情更清楚。 – RBarryYoung 2012-08-01 14:10:35

+0

我的答案(上面)是關於匹配列的數量和類型,是的。在我的評論中,我提到了這些名字。 – RBarryYoung 2012-08-01 14:13:25