以文本方式查看主题 - Foxtable(狐表) (http://foxtable.net/bbs/index.asp) -- 专家坐堂 (http://foxtable.net/bbs/list.asp?boardid=2) ---- /运行附近有语法错误 (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=187853) |
-- 作者:otterlike -- 发布时间:2023/8/16 17:33:00 -- /运行附近有语法错误 老师好!我写了一个代码,用于合并、保存数据表,运行后提示“/运行附近有语法错误.jpg”,我检查了所有代码里面没有出现过“/”,MessageBox.Show定位后,显示是代码:cmd.ExecuteNonQuery()有问题,请问该如何处理?谢谢! Dim dlg As New OpenFileDialog dlg.Filter = "Excel文件|*.xlsx|Excel文件|*.xls" dlg.MultiSelect = True \'允许选择多个文件 If dlg.ShowDialog = DialogResult.OK Then For Each fl As String In dlg.FileNames Dim mg As New Merger mg.Format = "excel" \'指定格式 mg.SourcePath = fl Dim Book As New XLS.Book(fl) Dim Sheet As XLS.Sheet = Book.Sheets(0) mg.SourceTableName = Sheet.name & "$" \'指定要合并的表 mg.DataTableName = "汽配费用查询表" \'指定接收数据的表 DataTables("汽配费用查询表").LoadFilter = "[_Identify] Is null" DataTables("汽配费用查询表").Load() mg.Merge() Next Dim stbl As String = "汽配费用查询表" \'合并数据后的查询表 Dim dtbl As String = "汽配费用" \'要保存的数据表 Dim cmd As New SQLCommand cmd.C \'外部数据源名称 Dim sql1, sql2 As String For Each c As Col In Tables(stbl).Cols sql1 + = c.Name & "," \'在VB.net中, a += b 等同于 a = a + b Next For Each r As Row In Tables(stbl).Rows sql2 = "" For Each c As Col In Tables(stbl).Cols If c.IsDate Then sql2 + = "\'" & r(c.Name) & "\'" & "," ElseIf c.IsString Then sql2 + = "\'" & r(c.Name) & "\'," ElseIf c.IsBoolean Then If r(c.Name) = True Then sql2 + = 1 & "," ElseIf r(c.Name) = False Then sql2 + = 0 & "," End If Else sql2 + = r(c.Name) & "," End If Next cmd.CommandText + = "InSert Into " & dtbl & " (" & sql1.Trim(",") & ") Values (" & sql2.Trim(",") & ");" Next cmd.CommandText = cmd.CommandText.Trim(";") \'CommandText字符型,用于设置SQL命令 MessageBox.Show(1) cmd.ExecuteNonQuery() \'ExecuteNonQuery用于执行不返回任何值的SQL命令,例如DELETE和UPDATE命令。该方法会返回一个整数,表示受影响的行数。 MessageBox.Show(2) DataTables(dtbl).Load \'加载目的数据表 End If |
-- 作者:有点蓝 -- 发布时间:2023/8/16 17:43:00 -- 弹出sql看看 cmd.CommandText = cmd.CommandText.Trim(";") msgbox(cmd.CommandText)
|
-- 作者:otterlike -- 发布时间:2023/8/18 7:53:00 -- 找到原因了,是因为系统中的数据表是通过导入生成的,列名中有“/”符号,谢谢老师! |