VB求帮助???
我们学完了VB但用代码连接数据库这段一点也没学。现在要用VB做一个客房管理系统。在连接数据库这段遇到极大困难不知道该从何下手。我做一个预定客房查询。要根据已入住和已预定客房的情况查询最近十天的客房状态。跟据未来几天的情况及时更新未来客户状态表并显示。
由于我不会VB用代码连接和更新数据库。下面是我根据别人的编 的一段代码错误很多。希望大家有空能于改下。
Set yd = cn.Execute("SELECT * FROM 客房预定表 ")
Set rz = cn.Execute("SELECT * FROM 入住登记表 ")
If yd.EOF And rz.EOF Then
yd.Close
rz.Close
rs.Close
Exit Sub
End If
If yd.EOF And Not rz.EOF Then
no = 0
End If
If rz.EOF And Not yd.EOF Then
no = 1
End If
If Not yd.EOF And Not rz.EOF Then
no = 2
End If
yd.Close
rz.Close
If no = 0 Then
' zz.LockType = adLockOptimistic
' zz.CursorType = adOpenKeyset
rz.LockType = adLockOptimistic
rz.CursorType = adOpenKeyset
rz.Open "入住登记表", cn, , , adCmdTable
'zz.Open "入住登记表", cn, , , adCmdTable
Set zz = cn.Execute("SELECT * FROM 临时客房状态表 ")
Set rz = cn.Execute("SELECT * FROM 临时客房状态表 ")
zz.MoveFirst
' And (rz.Fields("离店日期") >= Command2.Caption)
Do
'If rz.Find("房间号=" & "'" & zz.Fields("房间号") & "'" And "离店日期>" & "'" & Command2.Caption & "'") Then
zz.Update "房间状态", "已入住"
Else
zz.Update "房间状态", "空"
End If
zz.MoveNext
Loop Until zz.EOF
rz.Close
'zz.Close
End If
If no = 1 Then
zz.LockType = adLockOptimistic
zz.CursorType = adOpenKeyset
zz.Open "入住登记表", cn, , , adCmdTable
yd.LockType = adLockOptimistic
yd.CursorType = adOpenKeyset
yd.Open "预定登记表", cn, , , adCmdTable
Set zz = cn.Execute("SELECT * FROM 临时客房状态表 ")
zz.MoveFirst
Do
If yd.Find("房间号=" & "'" & zz.Fields("房间号") & "'") And yd.Fields("预离店日期") >= Command2.Caption And yd.Fields("预抵店日期") <= Command2.Caption Then
zz.Update "房间状态", "已预定"
Else: zz.Update "房间状态", "空"
End If
zz.MoveNext
Loop Until zz.EOF
yd.Close
zz.Close
End If
If no = 2 Then
zz.LockType = adLockOptimistic
zz.CursorType = adOpenKeyset
zz.Open "入住登记表", cn, , , adCmdTable
yd.LockType = adLockOptimistic
yd.CursorType = adOpenKeyset
rz.LockType = adLockOptimistic
rz.CursorType = adOpenKeyset
yd.Open "预定登记表", cn, , , adCmdTable
rz.Open "入住登记表", cn, , , adCmdTable
Set zz = cn.Execute("SELECT * FROM 临时客房状态表 ")
zz.MoveFirst
Do
If rz.Find("房间号=" & "'" & zz.Fields("房间号") & "'") And rz.Fields("离店日期") >= Command2.Caption Then
zz.Update "房间状态", "已入住"
Else:
If rz.Find("房间号=" & "'" & zz.Fields("房间号") & "'") And rz.Fields("离店日期") < Command2.Caption And yd.Find("房间号=" & "'" & zz.Fields("房间号") & "'") And yd.Fields("预抵店日期") >= Command2.Caption Or yd.Find("房间号=" & "'" & zz.Fields("房间号") & "'") And yd.Fields("预离店日期") < Command2.Caption Then
zz.Update "房间状态", "空"
End If
If yd.Find("房间号=" & "'" & zz.Fields("房间号") & "'") And yd.Fields("预抵店日期") > Command2.Caption And yd.Fields("预离店日期") < Command2.Caption Then
zz.Update "房间状态", "空"
End If
End If
zz.MoveNext
Loop Until zz.EOF
yd.Close
rz.Close
zz.Close
End If
Exit Sub
这是那个窗体
--------------------编程问答-------------------- 没空 --------------------编程问答-------------------- 自己先调试一下,什么问题,别人怎么知道你的数据库结构? --------------------编程问答-------------------- 代码乱.
脱离语言,先去看看sql server,把sql语句和算法理明白,初步估计你这一大段代码如果转换成sql语句估计就几行
补充:VB , 网络编程