| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 376 人关注过本帖
标题:哪错了???
取消只看楼主 加入收藏
dawn4640576
Rank: 1
等 级:新手上路
帖 子:1079
专家分:0
注 册:2007-9-19
收藏
 问题点数:0 回复次数:3 
哪错了???
Private Sub Command1_Click()
Dim rs As New ADODB.Recordset
Dim rs2 As New ADODB.Recordset
Dim cmd1 As New ADODB.Command
Dim cmd2 As New ADODB.Command
Dim str As String
Dim str2(0 To 2) As String
Call contooledb
Set cmd1.ActiveConnection = sqlcon
Set cmd2.ActiveConnection = sqlcon
cmd1.CommandText = "select * from xian1"
Set rs = cmd1.Execute

Open "D:\3.txt" For Input As #1
'Open "D:\4.txt" For Output As #2

Do While Not EOF(1)
Line Input #1, str
' Dim a As Long
'a = Len(str)
' 'MsgBox a
'Print #2, str
str2(0) = Trim(Mid$(str, 1, 10))
str2(1) = Trim(Mid$(str, 12, 1))
str2(2) = Trim(Mid$(str, 14, 4))
'Print #2, str2(1)
Do While Not rs.EOF
'Print #2, rs!id
If (rs!Type = str2(1)) Then
If (rs!date1 > rs!date2) Then
cmd2.CommandText = "update xian1 set date2 = '" & str2(0) & " ' where id= '" & rs!id & " ' "
cmd2.Execute
cmd2.CommandText = "update xian1 set weight2 = '" & str2(2) & " ' where id= '" & rs!id & " ' "
cmd2.Execute
Else
cmd2.CommandText = "update xian1 set date1='" & str2(0) & " ' where id= '" & rs!id & "'"
cmd2.Execute
cmd2.CommandText = "update xian1 set weight2=' " & str2(2) & " 'where id= '" & rs!id & "'"
cmd2.Execute
End If
End If
rs.MoveNext
'Print #2, rs!id
Loop
Loop
Close #1
rs.Close
MsgBox "更新成功!!"

我想更新表中的每个type字段,假设type有a和b两种类型,可当执行程序时,每次只能更新type为a的,为什么???????
我这个程序错在哪????



End Sub
2007-09-20 13:35
dawn4640576
Rank: 1
等 级:新手上路
帖 子:1079
专家分:0
注 册:2007-9-19
收藏
得分:0 
我知道了,第一次执行更新"a"时,记录集已经到了尾部,再执行时就不行了,只须在Do While Not rs.EOF后面加上一句:rs.movefirst就行了 !!!

我看青山多妩媚料青山看我应如是
2007-09-20 13:47
dawn4640576
Rank: 1
等 级:新手上路
帖 子:1079
专家分:0
注 册:2007-9-19
收藏
得分:0 
错了,是前面!!!

我看青山多妩媚料青山看我应如是
2007-09-20 13:47
dawn4640576
Rank: 1
等 级:新手上路
帖 子:1079
专家分:0
注 册:2007-9-19
收藏
得分:0 

我看青山多妩媚料青山看我应如是
2007-09-20 13:48
快速回复:哪错了???
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.021675 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved