解决文章中问题的具体步骤?

zhxu5215496 2004-03-13 10:04:22
公用模块:Model.bas
public username as string
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
On Error GoTo ExecuteSQL_Error
Stokens=Split(SQL)
Set cnn=New ADODB.Connection
cnn.Open ConnectString
If InStr(“INSERT,DELETE,UPDATE”, Ucase$(sTokens(0))) Then
Cnn.Execute SQL
MsgString=sTokens(0)&”query successful”
Else
Set rst=New ADODB.Recordset
Rst.Open Trim$(SQL),cnn,adOpenKeyset,AdLockOptimistic
Rst.MoveLast
Get recordcount
Set executeSQL=rst
Msgstring=”查询到”& rst.recordcount & “ 条记录”
End if
ExecuteSQL_Exit:
Set rst=nothing
Set cnn=nothing
Exit function
ExecuteSQL_error:
Msgstring=”查询错误:” & err.description
Resume executeSQL_Exit
End function
Public function connectstring() as string
connectstring=”fileDSN=studentinfo.dsn;UID=sa;_PWD=”
End function
Public function testtxt(txt as string) as Boolean
If trim(txt)=”” then
Testtxt=false
Else
Testtxt=true
End if
End function

Sub main()
Dim flogin as new frmlogin
Flogin.show vbmodal
If not flogin.ok then
Login failed so exit app
End
End if
Unload flogin
Set fmainform=new frmmain
Fmainform.show
End sub



有一登录窗口
登录窗口中各个控件的属性设置如下:
控件 属性 属性取值
Frmlogin(form) Name Frmlogin
Caption 登录
Startuppositon Centerscreen
windowstate Nomal
Txtusername name Txtusername
txtpassword name Txtpassword
name *
cmdok name Cmdok
caption 确定
cmdcancel name Cmdcancel
caption 取消
Label1 Caption 学生管理信息系统
Label2 Caption 用户名
Label3 Caption 用户密码
Option explicit
Public ok as Boolean
Dim micount as integer
Private sub form_load()
Ok=false
Micount=0
End sub

Private sub cmdok_click()
Dim txtSQL as string
Dim mrc as ADODB.recordset
Dim msgtext as string
Username=””
If trim(txtusername.txt=””) then
Msgbox “ !”,vbokonly+vbexclamation
Txtusernae.setfocus
Else
TxtSQL=”select * from user_info where user_ID=”” & txtusername.text & “”
Set mrc=executeSQL(txtSQL,msgtext)
If mrc.eof=true then
Msgbox “ !”,vbokonly+vbexclamation
Txtusername.setfocus
Else
If trim(mrc.fields(1))=trim(txtpassword.text) then
Ok=true
Mrc.close
Me.hide
Username=trim(txtusername.text)
Else
Msgbox “ !”,vbokonly+vbexclamation
Txtpassword.setfocus
Txtpassword.text=””
End if
End if
End if
Exit sub
End sub
Private sub cmdcancel_click()
Ok=false
Me.hide
End sub
数据库名为DB.mdb 数据表user_info
运行上述过程后,在if mrc.eof=true then语句 提示”对象变量或WITH块变量未设置”。请问怎么解决?请告诉具体步骤!





...全文
38 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
华芸智森 2004-03-13
  • 打赏
  • 举报
回复
TxtSQL=”select * from user_info where user_ID=”” & txtusername.text & “”


如果ID是字符型:
TxtSQL=”select * from user_info where user_ID='” & txtusername.text & "'"

如果ID是数字.
TxtSQL=”select * from user_info where user_ID=” & txtusername.text
rainstormmaster 2004-03-13
  • 打赏
  • 举报
回复
你的mrc对应的Connection呢?

7,789

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧