vb导入数据库提示sql语句错误,请帮忙更改,谢谢!
Option Explicit
Option Base 1
Dim cnn As ADODB.Connection
Private Sub Form_Load()
Set cnn = New ADODB.Connection
cnn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source= db.mdb" '连接数据源
cnn.ConnectionTimeout = 30
cnn.Open
End Sub
Private Sub Command1_Click()
Dim szsql$
Dim no, fsc
Open "1.txt" For Input As #1
Do While Not EOF(1)
Input #1, no, fsc
szsql = "insert into PD(no,fsc) values ('" & Trim(no) & "','" & Trim(fsc) & "')" cnn.Execute (szsql)
Loop
Close #1
cnn.CommitTrans
MsgBox "完成"
End Sub
数据库 vb
[解决办法]
no是什么类型的,如果是数字,不要引号
szsql = "insert into PD(no,fsc) values ('" & Trim(no) & "','" & Trim(fsc) & "')"
Debug.Print szsql
...
打开输出窗口,把sql贴出来。
[解决办法]
sql=" insert into 表名(字符型字段,数值型字段) values('"& 字符型变量 &"',"& 数值型变量 &")"