还没有人解决的问题

oupj 2003-04-26 01:24:04
本程序是从书上找到的.模块里的程序是:
Public Function ConnectString() _
As String
'returns a DB ConnectString
ConnectString = "FileDSN=studentinfo.dsn;UID=sa;PWD="
End Function
Public Function ExecuteSQL(ByVal SQL _
As String, MsgString As String) _
As ADODB.Recordset
'executes SQL and returns 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
---------------------------------------------------
调用该模块的程序是:
Private Sub cmdOK_Click()
Dim txtSQL As String
Dim mrc As ADODB.Recordset
Dim MsgText As String
UserName = ""
If Trim(txtUserName.Text = "") Then
MsgBox "用户名不能为空,请重新输入!", vbOKOnly + vbExclamation, "警告"
txtUserName.SetFocus
Else
'查询指定用户的记录
txtSQL = "select * from account where User_Name='" & txtUserName.Text & "'"
'执行查询语句
Set mrc = ExecuteSQL(txtSQL, MsgText)
If ***mrc.EOF = True*** Then
MsgBox "没有 " & txtUserName.Text & " 这个用户,请重新输入!", vbOKOnly + vbExclamation,

"警告"
txtUserName.SetFocus
Else
If Trim(mrc.Fields(2)) = 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
micount = micount + 1
If micount = 3 Then
Me.Hide
End If
Exit Sub
End Sub

***mrc.EOF = True ***为错误出处
出错代码:"实时错误“91”,对象变量或 with 块变量未设置"
我已引用了"microsoft activex data object2.7 library",但问题依然
...全文
25 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
oupj 2003-05-04
  • 打赏
  • 举报
回复
原来是
ConnectString = "FileDSN=studentinfo.dsn;UID=sa;PWD="
中UID=sa没空格惹的祸
chenyu5188 2003-05-04
  • 打赏
  • 举报
回复
书的例子只能看,不能照抄。
forrestsun 2003-05-04
  • 打赏
  • 举报
回复
还没有人解决的问题
你这个问题前两天就有人问我就写了:)
forrestsun 2003-05-04
  • 打赏
  • 举报
回复
Public Function ConnectString() _
As String
'returns a DB ConnectString
ConnectString = "DSN=studentinfo"
End Function

然后再ODBC中设一下DSN就可以了
我不太习惯向上面的写法,没用的信息就不要写了:)
oupj 2003-04-28
  • 打赏
  • 举报
回复
我自己解决了
VbKing 2003-04-26
  • 打赏
  • 举报
回复
Public Function ConnectString() _
As String
'returns a DB ConnectString
ConnectString = "FileDSN=studentinfo.dsn;UID=sa;PWD="
End Function
中FileDSN=studentinfo.dsn你做ODBC“studentinfo.dsn”的连接了吗?
DieGhost 2003-04-26
  • 打赏
  • 举报
回复
studentinfo.dsn 设置了没有???
980 2003-04-26
  • 打赏
  • 举报
回复
你是在vb数据库导航中拿来的

1,216

社区成员

发帖
与我相关
我的任务
社区描述
VB 数据库(包含打印,安装,报表)
社区管理员
  • 数据库(包含打印,安装,报表)社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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