dim strSql as string '定义SQL 查询语句接受变量
dim strConnectString as string '定义数据库连接字符串
dim rs as new adodb.recordset
strSql = "SQL 查询语句"
rs.CursorLocation = adUseClient
rs.LockType = adLockOptimistic
rs.CursorType = adOpenKeyset
rs.Open strSql, strConnectString
If rs.BOF = True And rs.EOF = True Then
rs.Close
Exit Function
Else
Set DataGrid1.DataSource = rs
Endif