【发布时间】:2013-12-27 02:06:03
【问题描述】:
至于我的问题,这是该死的代码..
Dim txt() As String
Dim _updateFlag As Boolean
Public Sub save()
Dim query = String.Empty
If Not _updateFlag Then
query = "INSERT INTO tblGPSRoutes(Time,Latitude,Longitude,Elevation,Accuracy,Bearing,Speed)"
query &= " VALUES ('" & txt(0) & "','" & txt(1) & "','" & txt(2) & "','" & txt(3) & "','" & txt(4) & "','" & txt(5) & "','" & txt(6) & "')"
databaseFunctions.ExecuteQuery(query)
MessageBox.Show("Data Saved Successfully.")
Else
query = String.Empty
query = "UPDATE tblGPSRoutes SET Time = '" & txt(0) & "', Latitude = '" & txt(1) & "', Longitude = '" & txt(2) & "', Elevation = '" & txt(3) & "', Accuracy = '" & txt(4) & "', Bearing = '" & txt(5) & "', Speed = '" & txt(6) & "' WHERE ID = " & Integer.Parse(textbox1.Text)
databaseFunctions.ExecuteQuery(query)
MessageBox.Show("Data Updated Successfully.")
End If
End Sub
它以我的其他形式工作。我只是在这里使用它,将值从 .Text 更改为数组中的值。
我从Try Catch“插入到语句中的语法错误”中得到了错误
我错过了什么吗?
顺便说一句,我使用 OleDB
更新:这些是 RichTextBox.Split(","c)
的值
04T16:18:42Z,14.524379,121.000830,60.700001,25.000000,350.299988,11.750000
在做save()之前,我在a上试过-
For each word in txt
MessageBox.Show(word)
Next
它完美地展示了他们每个人的分离。我的理论错了吗?
【问题讨论】:
-
由于您没有使用参数化查询,因此 [txt(n)] 值之一可能包含单引号。
-
由于我们看不到数组中的内容,其中之一可能是空白、null、无、包含保留字、非法字符或不良业力
-
更新了它。请检查
-
调试!在已完成的查询字符串上设置断点,将其复制/粘贴到 SQL 管理工作室或您使用的任何工具中,并检查数据库正在谈论的语法错误...
-
停止在 SQL 中使用文字并使用正确的参数!是的,是不是又快又容易,却会给你带来各种问题。