vb中如何判断一个表是否为空
2个回答
展开全部
如果你是使用ADO控件来连接数据库,那么这样:
If Adodc1.Recordset.RecordCount = 0 Then MsgBox "这个数据表是空的!!"
如果是使用ADODB对象来连接数据库的(像下面那样):
Dim Conn As New ADODB.Connection
Dim Rs As New ADODB.Recordset
Set Conn = New ADODB.Connection
Conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\tada.mdb;Persist Security Info=False"
Set Rs = New ADODB.Recordset
Rs.Open "Select * from data", Conn, adOpenKeyset, adLockOptimistic
那么这样:
If Rs.RecordCount = 0 Then MsgBox "这个数据表是空的!!"
If Adodc1.Recordset.RecordCount = 0 Then MsgBox "这个数据表是空的!!"
如果是使用ADODB对象来连接数据库的(像下面那样):
Dim Conn As New ADODB.Connection
Dim Rs As New ADODB.Recordset
Set Conn = New ADODB.Connection
Conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\tada.mdb;Persist Security Info=False"
Set Rs = New ADODB.Recordset
Rs.Open "Select * from data", Conn, adOpenKeyset, adLockOptimistic
那么这样:
If Rs.RecordCount = 0 Then MsgBox "这个数据表是空的!!"
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询