vb.net...我在使用访问时做错了什么 [英] vb.net... What am i doing wrong working with access

查看:22
本文介绍了vb.net...我在使用访问时做错了什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题是在 da.Update(dt).我收到 OleDbException 未处理.INSERT INTO 语句中的语法错误.奇怪的是它之前运行过,当我只保存 10 个项目时,现在它根本不运行了.感谢您的帮助.

My probelm is at da.Update(dt). I recieve OleDbException was unhandled. Syntax error in INSERT INTO statement. The weird thing is it ran before when I was only saving 10 items and now it doesn't run at all quite confused. Thanks for any assistance.

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

推荐答案

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

This is the error that you get when your Item's count and/or datatype's do not match the column definitions of the table that you are writing to. There are other possibilities, but since you mentioned that you added more items, and you have not shown us the table definition, that seems the most likely possibility.

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

You cannot just add more items (columns) to a database command, they have to match the table columns that you are reading/writing from/to.

这篇关于vb.net...我在使用访问时做错了什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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