数据库为空时怎么办?
数据库为空时怎么办?就是这个意思:
mySQL = "select * from " & wagedatabase & " where TBData='" & wageny & "' and Dept='" & wagedept & "'"
其中TBData and Dept 为空的,我想让txt(i)都为空,并且提示”该记录为空,可以添加数据!“怎么编写?
下面是部分原码:
Set RsAdo = New ADODB.Recordset
mySQL = "select * from " & wagedatabase & " where TBData='" & wageny & "' and Dept='" & wagedept & "'"
RsAdo.Open mySQL, AdoCon, adOpenDynamic, adLockReadOnly
txt(24).Text = RsAdo!tbdata & ""
txt(1).Text = RsAdo!Duty & ""
txt(0).Text = RsAdo!Population & ""
txt(2).Text = RsAdo!AveDuty & ""
txt(3).Text = RsAdo!Uoutput & ""
For i = 0 To 33
If txt(i) = "" Then
txt(i) = ""
MsgBox " 该项还没有记录,可以添加", vbOKCancel, " 查看记录"
End If
Next
当然下面的判断处不对啦,还望大家帮我改改。 --------------------编程问答-------------------- Set RsAdo = New ADODB.Recordset
mySQL = "select * from " & wagedatabase & " where TBData='" & wageny & "' and Dept='" & wagedept & "'"
RsAdo.Open mySQL, AdoCon, adOpenDynamic, adLockReadOnly
If Not RsAdo.EOF Then
txt(24).Text = RsAdo!tbdata & ""
txt(1).Text = RsAdo!Duty & ""
txt(0).Text = RsAdo!Population & ""
txt(2).Text = RsAdo!AveDuty & ""
txt(3).Text = RsAdo!Uoutput & ""
Else
MsgBox " 该项还没有记录,可以添加", vbOKCancel, " 查看记录"
End If --------------------编程问答-------------------- 楼主好象不是这意思,是说字段没值才可以添加吧??? --------------------编程问答-------------------- Set RsAdo = New ADODB.Recordset
mySQL = "select * from " & wagedatabase & " where TBData='" & wageny & "' and Dept='" & wagedept & "'"
RsAdo.Open mySQL, AdoCon, adOpenDynamic, adLockReadOnly
if rsado.recordcount>0 then
txt(24).Text = RsAdo!tbdata & ""
txt(1).Text = RsAdo!Duty & ""
txt(0).Text = RsAdo!Population & ""
txt(2).Text = RsAdo!AveDuty & ""
txt(3).Text = RsAdo!Uoutput & ""
endif
补充:VB , 数据库(包含打印,安装,报表)