急!!!!请问每句语句的含义,帮忙解释一下~!~!~!~!
这是写在DataBaseModule中的语句,请问每一句的含义是什么啊??
Public u_name As String
Public u_pass As String
Public strSql As String
Public MsgStr As String
Public rs As ADODB.Recordset
Public Function ConnectString() As String
ConnectString = "FileDSN=.\my_factory.dsn;UID=admin;PWD= "
End Function
Public Function ExecuteSQL(ByVal SQL As String, MsgString As String) As ADODB.Recordset
Dim cnn As ADODB.Connection
Dim rst As ADODB.Recordset
Dim sTokens() As String
sTokens = Split(SQL, " ")
Set cnn = New ADODB.Connection
cnn.Open ConnectString
If InStr( "insert,delete,update ", sTokens(0)) > 0 Then
cnn.Execute (SQL)
Else
Set rst = New ADODB.Recordset
rst.Open Trim$(SQL), cnn, adOpenKeyset, adLockOptimistic
Set ExecuteSQL = rst
Set rst = Nothing
Set cnn = Nothing
End If
End Function
Public Sub Msg_Box(ByVal MsgString As String)
MsgBox MsgString, vbOKOnly, "提示 "
End Sub
Public Function Msg_Boxs(ByVal MsgString As String) As Boolean
If MsgBox(MsgString, vbOKCancel, "提示 ") = vbOK Then
Msg_Boxs = True
Else
Msg_Boxs = False
End If
End Function
[解决办法]
Public u_name As String '用户变量
Public u_pass As String '密码变量
Public strSql As String '查询语句变量
Public MsgStr As String '提示消息变量
Public rs As ADODB.Recordset '申明记录集
'联接数据库的字符串函数
Public Function ConnectString() As String
ConnectString = "FileDSN=.\my_factory.dsn;UID=admin;PWD= "
End Function
'执行SQL语句的函数,带两个参数,一个是查询语句,一个是提示的消息
Public Function ExecuteSQL(ByVal SQL As String, MsgString As String) As ADODB.Recordset
Dim cnn As ADODB.Connection '申明的数据库联接
Dim rst As ADODB.Recordset '申明的记录集
Dim sTokens() As String '申明的字符串数组
sTokens = Split(SQL, " ") '对字符串数组用Split函数按空格分隔
Set cnn = New ADODB.Connection '激活数据库联接
cnn.Open ConnectString '打开数据库
If InStr( "insert,delete,update ", sTokens(0)) > 0 Then '当查询语句中出现 Insert Delete Update时,则使用Execute 的方法执行
cnn.Execute (SQL) '执行SQL语句
Else
Set rst = New ADODB.Recordset
rst.Open Trim$(SQL), cnn, adOpenKeyset, adLockOptimistic '如果是Select则用OPen方法执行SQL语句,并返回记录集,后面是游标类型和锁类型
Set ExecuteSQL = rst '为函数返回记录集
Set rst = Nothing '释放内存
Set cnn = Nothing '释放内存
End If
End Function
Public Sub Msg_Box(ByVal MsgString As String)
MsgBox MsgString, vbOKOnly, "提示 "
End Sub
'消息函数,返回为布尔值
Public Function Msg_Boxs(ByVal MsgString As String) As Boolean
If MsgBox(MsgString, vbOKCancel, "提示 ") = vbOK Then
Msg_Boxs = True
Else
Msg_Boxs = False
End If
End Function
[解决办法]
一个是记录集,一个是连接对象,记录集要通过连接对象来访问连接的数据库中的数据。
具体的你可以查看MSDN。