1

我的问题在 da.Update(dt)。我收到 OleDbException 未处理。INSERT INTO 语句中的语法错误。奇怪的是它在我只保存 10 个项目之前运行,现在它运行起来一点也不混乱。感谢您的任何帮助。

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()
4

1 回答 1

0

这是当您的项目计数和/或数据类型与您正在写入的表的列定义不匹配时出现的错误。还有其他可能性,但是由于您提到您添加了更多项目,并且您没有向我们展示表定义,所以这似乎是最有可能的可能性。

您不能只向数据库命令添加更多项目(列),它们必须与您正在读取/写入的表列相匹配。

于 2012-08-01T13:57:39.763 回答