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中?各位大侠帮帮忙!
解决后还有追加! 展开
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中?各位大侠帮帮忙!
解决后还有追加! 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询