超烦INSERT INTO语句,请大侠帮忙。

fgfdg33 2003-05-19 11:48:40
我想向表中插入数据,但有很多字段,我写了一条INSERT语句,但出错了,请各位帮忙修改一下,谢谢。另有没有更好的方法,请告诉我。

Dim txtInsert As String
Dim rstInsert As New ADODB.Recordset

Dim ValLid, ValDoctorID, ValDruggistID, ValFactory, ValPackge As String
Dim ValSpecs, ValFoemNo, ValPlace, ValProvider As String
Dim ValTradeMark, ValLicenceNo, ValFacies, ValPackgeQualty, ValVerdict, ValMemo As String
Dim ValEntryDate, ValValidDate, ValSpendDate As Date
Dim ValTotalCharge, ValPrice As Currency
Dim ValTotalAmount, ValTotalNice, ValNice, ValSToreAmount, ValStoreNice As Integer


txtInsert = "INSERT INTO LeechdomStock (LeechdomID,Factory,Entrydate,ValidDate," _
& "TotalCharge,TotalAmount,TotalNice,Nice,Price,StoreAmount,StoreNice," _
& "Packge,Specs,DoctorID,DruggistID,FormNO,Place,SpendDate,Provider," _
& "TradeMark,LicenceNo,Facies,PackgeQuality,Verdict,Memo)" _
& "VALUES('" & ValLid & "','" & ValFactory & "',#" & ValEntryDate & "#,#" _
& ValValidDate & "#," & ValTotalCharge & "," & ValTotalAmount & "," _
& ValNice & "," & ValTotalNice & "," & ValPrice & "," & ValSToreAmount & "," _
& ValStoreNice & ",'" & ValPackge & "','" & ValSpecs & "','" & ValDoctorID _
& "','" & ValDruggistID & "','" & ValFormno & "','" & ValPlace & "',#" _
& ValSpendDate & "#,'" & ValProvider & "','" & ValTradeMark & "','" _
& ValLicenceNo & "','" & ValFacies & "','" & ValPackgequality & "','" _
& ValVerdict & "','" & ValMemo & "')"


运行到此处时出错语句是“INSERT INTO 语法错误”
rstInsert.Open txtInsert, Cnn, adOpenStatic, adLockOptimistic


...全文
28 点赞 收藏 3
写回复
3 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
刘如心 2003-05-20
你把这一条语句放到SQL查询分析器中执行,就知道错在那了,如果你不时很清楚SQL你可以从我这http://211.102.2.245下载一本SQL编程指南
回复
lihonggen0 2003-05-20
运行到此处时出错语句是“INSERT INTO 语法错误”
rstInsert.Open txtInsert, Cnn, adOpenStatic, adLockOptimistic



改为

Cnn.execute txtInsert

还有就是请检查你的插入语句,是否正确
回复
饮水需思源 2003-05-20
执行:cnn.execute txtinsert
字符型变量的引用:'" & 变量名 & "'
数值型变量的引用: " & 变量名 & "
语句之间的连接最好用空格隔开:(例如)
& " TradeMark,LicenceNo,Facies,PackgeQuality,Verdict,Memo) " _
& " VALUES('" & ValLid & "','" & ValFactory & "',#" & ValEntryDate

回复
相关推荐
发帖
VB基础类
创建于2007-09-28

7491

社区成员

VB 基础类
申请成为版主
帖子事件
创建了帖子
2003-05-19 11:48
社区公告
暂无公告