如何学好数据库技术?
发布网友
发布时间:2022-04-23 23:31
我来回答
共2个回答
热心网友
时间:2023-10-07 03:31
首先我不是高手
但是过了数据库*了
首先只要自己对它有兴趣
其次要对自己有信心
买本基础一点的书,从头学起
多思考,多练习就可以了
个人认为电子书籍不如自己买本书来读效果好
祝你好运~
热心网友
时间:2023-10-07 03:31
下面是一个连接数据库的模块,大家可以使用它来连接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