adodc1 的问题 我的代码如下

PrivateSubCommand2_Click()Dimcowno(1000)AsStringDimtrans(1000)AsStringDimaver1(1000)A... Private Sub Command2_Click()
Dim cowno(1000) As String
Dim trans(1000) As String
Dim aver1(1000) As String
Dim aver2(1000) As String
Dim aver3(1000) As String
Dim dura1(1000) As String
Dim dura2(1000) As String
Dim dura3(1000) As String
Dim milkyes1(1000) As String
Dim milkyes2(1000) As String
Dim milkyes3(1000) As String
Dim mpcyes1(1000) As String
Dim mpcyes2(1000) As String
Dim mpcyes3(1000) As String
Adodc1.Refresh

Do While Adodc1.Recordset.EOF = False
Dim i As Integer
i = 0
cowno(i) = Adodc1.Recordset("CowNo")
tran(i) = Adodc1.Recordset("Transponder")
ave1(i) = Adodc1.Recordset("AverFlowY1")
ave2(i) = Adodc1.Recordset("AverFlowY2")
ave3(i) = Adodc1.Recordset("AverFlowY3")
dur1(i) = Adodc1.Recordset("DurationY1")
dur2(i) = Adodc1.Recordset("DurationY2")
dur3(i) = Adodc1.Recordset("DurationY3")
milkye1(i) = Adodc1.Recordset("MilkYesterday1")
milkye2(i) = Adodc1.Recordset("MilkYesterday2")
milkye3(i) = Adodc1.Recordset("MilkYesterday3")
mpcye1(i) = Adodc1.Recordset("MPCYesterday1")
mpcye2(i) = Adodc1.Recordset("MPCYesterday2")
mpcye3(i) = Adodc1.Recordset("MPCYesterday3")
i = i + 1
Adodc1.Recordset.MoveNext
Loop
Set cnn = CreateObject("ADODB.Connection")
cnn.ConnectionString = "Driver={SQL Server};Server=sqlserver;database=alpro;uid=sa;pwd=down2load"
cnn.Open
'取得结果集并导入数据
Set rs = CreateObject("ADODB.recordset")
rs.Open " insert into milk (cowno,trans,averflowy1,averflowy2,averflowy3,durationy1,durationy2,durationy3,milkyesterday1,milkyesterday2,milkyesterday3,mpcyesterday1,mpcyesterday2,mpcyesterday3) values('" & cowno & "','" & tran & "','" & ave1 & "','" & aver & "','" & ave3 & "','" & dur1 & "','" & dur2 & "','" & dur3 & "','" & milkye1 & "','" & milkye2 & "','" & milkye3 & "','" & mpcye1 & "','" & mpcye2 & "','" & mpcye3 & "')", cnn, 0

'关闭连接,回收资源
cnn.Close

Set cnn = Nothing
Set rs = Nothing

MsgBox "OK!上传成功!"

End Sub

利用这个代码。为什么我只能导入一行数据进入sql中?各位大侠帮帮忙!

解决后还有追加!
展开
 我来答
老人与孩v动手洞脑
2009-03-24 · TA获得超过599个赞
知道小有建树答主
回答量:400
采纳率:0%
帮助的人:331万
展开全部
你把 Dim i As Integer 放到循环外面,然后将i=0 去掉就行了
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式