vb操作数据库的一点小问题,高手请留步~
我创建了个sql2008的数据库,并且已经连接上现在我想对其中的一个表进行操作,表易做图有9个字段,rs(0)--rs(8)
其中,我想根据rs(2)和rs(3)的值决定rs(8)的值,是对整个表中所有行都进行此操作哦!!不是找到其中一个行进行修改~~!!!
Private Sub Form_Load()
Form1.Height = 8500
Form1.Width = 14000
Set Rs = New ADODB.Recordset
Set Cn = New ADODB.connection
cnstr = "provider=sqloledb;User ID = sa;password = 880805;initial catalog = 小区物业管理;Data Source = WAXSNYBB\WAXSN"
Rs.CursorLocation = adUseClient
Cn.Open cnstr
sql = "select * from 物业收费信息 order by 业主编号 asc"
Rs.Open sql, Cn, adOpenDynamic, adLockOptimistic
End Sub
Private Sub Command3_Click()
If Rs(2) <= Rs(3) Then
Rs(8) = "开"
Else
Rs(8) = "关"
End If
Rs.Update
End Sub
大概就是这个意思,可是我运行点击command3之后,没反应啊,怎么回事腻~~ --------------------编程问答-------------------- 高手们呢~在线跪等呢呀~ --------------------编程问答--------------------
Private Sub Form_Load()
Form1.Height = 8500
Form1.Width = 14000
Set Rs = New ADODB.Recordset
Set Cn = New ADODB.connection
cnstr = "provider=sqloledb;User ID = sa;password = 880805;initial catalog = 小区物业管理;Data Source = WAXSNYBB\WAXSN"
Rs.CursorLocation = adUseClient
Cn.Open cnstr
'sql = "select * from 物业收费信息 order by 业主编号 asc"
'Rs.Open sql, Cn, adOpenDynamic, adLockOptimistic
End Sub
Private Sub Command3_Click()
'直接用SQL语句更新
sql=" UPDATE 物业收费信息 SET 字段8=CASE WHEN 字段2<=字段3 THEN '开' ELSE '关' END "
cn.execute sql
msgbox "更新成功!",vbokonly,"提示"
End Sub
--------------------编程问答-------------------- sql=" UPDATE 物业收费信息 SET 字段8=字段2+字段3
cn.execute sql
补充:VB , 数据库(包含打印,安装,报表)