1、使用GridView控件绑定该数据源。
2、添加计数器添加SQL的常用统计然后在下面列出的项目里面选择用户连接就可以时时查询到数据库的连接数了。
你有数据库吗?连接你的数据库的位置,加他的 连接条件就可以拉下面是一个连接数据库的模块,大家可以使用它来连接SQL数据库,使用起来比ADO控件还简单:
代码如下:
Public rsNew As ADODB.Recordset
Public CnNew As ADODB.Connection
Public addFlag As Boolean
'连接数据库
Public Function OpenCn() As Boolean
Dim Mag As String
On Error GoTo strErrMag
Set CnNew = New ADODB.Connection
CnNew.ConnectionTimeout = 25
CnNew.Provider = "sqloledb"
CnNew.Properties("data source").value = "" 'SQL服务器的名
CnNew.Properties("initial catalog").value = "pubs"'库名
CnNew.Properties("integrated security").value = "SSPI"'登陆类型
'con.Properties("user id").value = "sa"
'con.Properties("password").value = "wwww"
CnNew.Open
OpenCn = True
addFlag = True
Exit Function
strErrMag:
Mag = "数据库末连接"
Call MsgBox(Mag, vbOKCancel, "错误:数据库连接")
addFlag = False
End
End Function
Public Sub Clocn()
'闭关数据库
On Error Resume Next
If CnNew.State <>adStateClosed Then CnNew.Close
Set CnNew = Nothing
End Sub
Public Function OpenRs(ByVal strSql As String) As Boolean
'连接数据库记录集
Dim Mag As String
Dim rpy As Boolean
On Error GoTo strErrMag
Set rsNew = New ADODB.Recordset
If addFlag = False Then rpy = OpenCn
With rsNew
.ActiveConnection = CnNew
.CursorLocation = adUseClient
.CursorType = adOpenKeyset
.LockType = adLockOptimistic
.Open strSql
End With
addFlag = True
OpenRs = True
Exit Function
strErrMag:
Mag = "数据库数据集末连接"
Call MsgBox(Mag, vbOKOnly, "错误:数据库连接")
OpenRs = False
End
End Function
Public Sub cloRs()
'闭关数据集
On Error Resume Next
If rsNew.State <>adStateClosed Then rsNew.Close
Set rsNew = Nothing
End Sub
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)