|
7#
楼主 |
发表于 2008-2-4 14:05:06
|
只看该作者
回复 9# 的帖子
'连接数据库的函数
Public Function GetNewConnection() As ADODB.Connection
Dim oCn As New ADODB.Connection
Dim sCnStr As String
sCnStr = "Provider='sqloledb';Data Source='wangqiang';" & _
"Initial Catalog='accesstata';Integrated Security='SSPI';user_id='sa';password='120979120979'"
oCn.Open sCnStr
If oCn.State = adStateOpen Then
Set GetNewConnection = oCn
End If
End Function
'登录按钮代码
Private Sub Command6_Click()
Dim cn As ADODB.Connection
Dim rx As ADODB.Recordset
user_online = 1
Set cn = GetNewConnection
If IsNull(Text2) Or IsNull(Text4) Then
MsgBox "没有输入用户名或密码,请重新输入", vbInformation, "系统提示"
Exit Sub
End If
rx.Open "select * from user_tbl where [user_name]='" & Text2 & " ' and [user_password]=' " & Text4 & "'", cn, adOpenKeyset, adLockBatchOptimistic
If rx.EOF Then
MsgBox "你输入的用户名或密码错误,请重新输入!" & Chr(10) & Chr(13) & "如果您还没有注册,请点击注册按钮!", vbCritical, "系统提示"
Me.Text2.Value = ""
Me.Text4.Value = ""
Me.Text2.SetFocus
Exit Sub
Else
user_name = Me.Text2.Value
user_id = rx(user_id)
user_level = rx(user_level)
user_online = 2
DoCmd.Close
DoCmd.OpenForm "网络留言簿系统", acNormal
End If
rx.Close
Set rx = Nothing
End Sub
我的后台数据库是SQL SEVER 2000
上午试了一上午,在接近中午的时候没有问题,但一冲动就忘记保存代码了,下午一写,又提示出错了,这次的提示是:对象变量或WITH块变量未设置
晕倒了 |
|