收购玛瑙原石2公斤以上:vb(问题请教!!!!)

来源:百度文库 编辑:杭州交通信息网 时间:2024/04/28 10:53:51
Public conn As New ADODB.Connection '连接数据库方式
Public rs As New ADODB.Recordset '数据库结果集(执行结果)
Public strSQL As String

Public Function ConnectToDB() As Boolean '连接数据库函数
conn.ConnectionString = "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;pwd=;Initial Catalog=pubs"
conn.ConnectionTimeout = 10
conn.Open
If conn.State = 1 Then
ConnectToDB = True
Else
ConnectToDB = False
End If
End Function

Public Sub DisConnect() '关闭连接
If conn.State = 1 Then '判断是否已经建立
conn.Close
End If
End Sub

Public Function Login(strUser As String, strPWD As String) As Boolean
strSQL = "select count(*) as cnt from login where userid='" & strUser & "' and pwd='" & strPWD & "'"
Login = False
If ConnectToDB = True Then
If ExecuteSQL(strSQL) Then
If rs!cnt = 1 Then
MsgBox "登录成功"
Login = True
Else
MsgBox "用户名或密码错误!"
End If
End If
Else
MsgBox "连接数据库失败"
End If
End Function

Public Function ExecuteSQL(strSQL As String) As Boolean '执行数据库
On Error Resume Next '忽略错误
Set rs = conn.Execute(strSQL) '验证数据库集能否正常运行
If Err.Number <> 0 Then '如果出错
ExecuteSQL = False
MsgBox "执行SQL语句出错" 'Err.Description
Err.Clear '清空
Else
ExecuteSQL = True
End If
End Function

问题(1)
第一行的recordest数据库集到底是怎们回事,还有StrSQL设置是放用户名和密码吗?
问题(2)
第23行的If ExecuteSQL(strSQL) Then 是怎们回事,难道是判断用户名和密码吗?
问题(3)
第37行的Set rs = conn.Execute(strSQL)是设置什么?

问题(1)
第一行的recordest数据库集到底是怎们回事,还有StrSQL设置是放用户名和密码吗?
数据库集是Adodb的一种数据库访问方式,是高级语言代码与数据库数据间的桥梁。简言之,你要访问数据库里的数据就必须建立一个数据库集。
StrSQL不是放用户名和密码的 是放SQL查询语言的句子的

问题(2)
第23行的If ExecuteSQL(strSQL) Then 是怎们回事,难道是判断用户名和密码吗?
ExecuteSQL(strSQL) 是按照strSQL里面所描述进行数据库查询,比如要在哪张表查询哪一列的数据。ExecuteSQL(strSQL)返回查询过程中是否出错。

问题(3)
第37行的Set rs = conn.Execute(strSQL)是设置什么?
设置数据集,名字叫rs,rs就相当于strSQL中指定的数据集合。