2012-08-01 79 views
0

我的问题发生在da.Update(dt)。我收到“OleDbException was unhandled,INSERT INTO语句中的语法错误”错误。它工作时,我用一个没有字段名称和只有10列的基本表,但现在我有25个项目不起作用。Vb.net问题更新数据库

Dim dt As New DataTable 
    Dim ds As New DataSet 

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

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

    Dim da As New OleDbDataAdapter 

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

    da.Fill(dt) 



    Dim newRow As DataRow = dt.NewRow 

    newRow.Item("Caller") = Caller 
    newRow.Item("Associate Name") = Associate 
    newRow.Item("Store Number") = "1" 
    newRow.Item("Number of Rings") = Ring 
    newRow.Item("Time on Hold") = HoldTime 
    newRow.Item("Greeting: 3 or fewer rings") = GreetingRings 
    newRow.Item("Greeting: Asked for your name") = GreetingAskName 
    newRow.Item("Greeting: Offered his/her name") = GreetingOfferedName 
    newRow.Item("Greeting: Mentioned TIRE PROS in the greeting") = GreetingTirePros 
    newRow.Item("Greeting: Associated acted like they are glad") = GreetingGlad 
    newRow.Item("Hold for longer than 1 minute") = holdUpdate 
    newRow.Item("Ask for the type of car AND look up the size") = LookupSize 
    newRow.Item("Ask appropriate questions about the type of driving") = DailyDriving 
    newRow.Item("1st Price Mentioned") = SingleTirePrice 
    newRow.Item("1st OTD Price Mentioned") = SingleTireOutDoorPrice 
    newRow.Item("Tire Brand") = TireBrand 
    newRow.Item("Tire Model") = TireModel 
    newRow.Item("Offered several tire choices and prices") = SeveralChoices 
    newRow.Item("Did they offer financing options") = Financing 
    newRow.Item("Mentioned benefits of the location") = Benefits 
    newRow.Item("Appointment") = Appointment 
    newRow.Item("How long does it take to put them on") = InstallTime 
    newRow.Item("Associate Score") = AssociateScore 
    newRow.Item("Time Completed") = hms 
    newRow.Item("Completed Date") = ymd 



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

可能重复的[vb.net ...我做错了与访问工作](http://stackoverflow.com/questions/11760663/vb-net-what-am-i-doing-wrong-working与访问) – LarsTech 2012-08-01 16:19:55

+0

很难说如果没有看到你的表定义。它可以是任何数量的东西,例如'ymd'不是一个日期,'Store Number'不是一个字符串,你试图分配给一个标识列...我只是猜测,直到我们可以看到表。 – Widor 2012-08-01 16:22:25

+0

@LarsTech:这不是该问题的重复,而是后续。 – RBarryYoung 2012-08-01 16:22:28

回答

0

错误“INSERT INTO语句中的语法错误”可能意味着问题是,使用OLEDB命令生成器不能正确处理您使用的列名。这些行:

你有“非可变式的”列名,这基本上是任何类型的名字,你不能也作为变量名使用的
newRow.Item("Store Number") = "1" 
    newRow.Item("Number of Rings") = Ring 
    newRow.Item("Time on Hold") = HoldTime 
    newRow.Item("Greeting: 3 or fewer rings") = GreetingRings 
    newRow.Item("Greeting: Asked for your name") = GreetingAskName 
    newRow.Item("Greeting: Offered his/her name") = GreetingOfferedName 
    newRow.Item("Greeting: Mentioned TIRE PROS in the greeting") = GreetingTirePros 
    newRow.Item("Greeting: Associated acted like they are glad") = GreetingGlad 

显示。那只是{A-Z,0-9和“_”}。事情就像他们严禁可变式的名字不是无效的,但他们有专门引用,就像这样:

newRow.Item("[Store Number]") = "1" 

不幸的是,一些连接提供商(我认为的OleDb就是其中之一这种情况下),不能处理,并会取消引用他们,导致生成的SQL命令无效。

最简单的解决方案是回到列号而不是名称(可能原因是他们原来的原因)。或者,您可以重命名所有列名称以删除所有非变量类型的字符(空格,冒号等)。

+0

好的。那么我一直在做什么,并且评论大部分内容,并存储到一个新的数据库中,并添加到列以访问和两个新变量,并查看失败发生的位置。现在,现在有错误了。 – Jbailey01 2012-08-01 17:44:38