调用时参数错误了.
Set rs = getrs("strsql")
txtname.Text = rs("name")——————>这句出问题了,错误如题目所示!
txtdepartnum.Text = rs("department")
strsql1 = "select name from department where id='" &rs("department") &"'"
Set rs1 = getrs("strsql1")
把这上面中getrs的参数上的引号去掉:
set rs=getrs(strsql)
......
set rs=getrs(strsql1)
给你一个ADO控件 或对象的数据库连接代码看看Dim adocnn As ADODB.Connection
Dim adorst As ADODB.Recordset
Dim mdbpath As String
Dim cnnstr As String
Dim sqlstr As String
Set adocnn = New ADODB.Connection
Set adorst = New ADODB.Recordset
adorst.CursorLocation = adUseClient
mdbpath = App.Path &"\playlist.mdb"
cnnstr = "Provider=Microsoft.Jet.OLEDB.4.0Data Source=" &mdbpath &"Persist Security Info=False"
sqlstr = "Select * from playlist"
adocnn.Open cnnstr
adorst.Open sqlstr, adocnn, adOpenKeyset, adLockOptimistic
jlistmax = Filelist.ListCount - 1
If typecomb.Text = "*.mp3" Then
songtype = "MP3"
ElseIf typecomb.Text = "*.wma" Then
songtype = "WMA"
ElseIf typecomb.Text = "*.mdi" Then
songtype = "MDI"
Else: typecomb.Text = "*.wav"
songtype = "WAV"
End If
songpath = Dirlist.Path
For ilist = 0 To jlistmax
adorst.AddNew
songname = Filelist.List(ilist)
i = InStr(1, songname, ".")
songname = Left(songname, i - 1)
adorst.Fields("歌曲名") = songname
adorst.Fields("歌曲存储地址") = songpath
adorst.Fields("歌曲文件格式") = songtype
adorst.Update
Next ilist
adorst.Close
adocnn.Close
你的主要问题是if..then..end if逻辑关系混乱,以至于数据库已经关闭了,还在想要读取字段值,修改如下:Private Sub Command1_Click()
If Text1.Text = "" Then
MsgBox "用户名不能为空,请重新输入!"
Text1.SetFocus
Exit Sub
End If
If Text2.Text = "" Then
MsgBox "密码不能为空,请输入!"
Text2.SetFocus
Exit Sub
End If
rsyz.CursorLocation = adUseClient
rsyz.Open "select * from [user] where userid='" &Text1.Text &"'", cnyz, adOpenDynamic, adLockOptimistic
If rsyz.RecordCount = 0 Then
n = n + 1
If n <3 Then
MsgBox "无此用户名,请注册或重新输入!"
Else
MsgBox "您输入的密码错误次数已经达到3次,请稍后再试!"
rsyz.Close
Set rsyz = Nothing
End
End If
Text1.Text = ""
Text1.SetFocus
rsyz.Close
Set rsyz = Nothing
Exit Sub
Else
If Trim(Text2.Text) <>rsyz.Fields("userpassword") Then
n = n + 1
If n <3 Then
MsgBox "您输入的账号或密码错误,请重新输入!"
Text2.Text = ""
Text2.SetFocus
rsyz.Close
Set rsyz = Nothing
Exit Sub
Else
MsgBox "您输入的账号或密码错误次数已经达到3次,请稍后再试!"
rsyz.Close
Set rsyz = Nothing
End
End If
Else
Select Case rsyz.Fields("usertype")'就这句有问题。。搞不懂
Case "stu"
stu.Show
Case "tea"
tea.Show
End Select
rsyz.Close
Set rsyz = Nothing
End If
End If
End Sub
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)