登录卡在了 这句【If mrc.EOF Then ...】代码上......

我是一道光_ 2009-07-23 09:12:44
如题,我们近期做的一个实例,就是很普遍的 学生信息管理系统,这是个入门缓冲的很不错的实例。

如下,只是frmLogin 窗体的全部代码,其中用到模块里的函数,经检查是没有问题的。通过源代码试验和本人的浅显调试,和数据库的连接还是不成问题的,因为跳过用户名(检查用户名这块儿代码),是可以进入系统的。
就是一开始卡在了这个用户名的检查上。
(我想是这样的。)

小弟,新学数据库,很多不懂,还望各位大虾,多多帮衬哈~~




Private Sub Form_Load()
Dim sBuffer As String
Dim lSize As Long


sBuffer = Space$(255)
MsgBox sBuffer & "adfa"
lSize = Len(sBuffer)
Call GetUserName(sBuffer, lSize)
If lSize > 0 Then
MsgBox lSize
txtUserName.Text = ""

Else
txtUserName.Text = vbNullString
End If


OK = False
miCount = 0
End Sub



Private Sub cmdCancel_Click()
OK = False
Me.Hide
End Sub


Private Sub cmdOK_Click()
Dim txtSQL As String
Dim mrc As ADODB.Recordset
Dim MsgText As String
'ToDo: create test for correct password
'check for correct password

UserName = ""
If Trim(txtUserName.Text = "") Then
MsgBox "没有这个用户,请重新输入用户名!", vbOKOnly + vbExclamation, "警告"
txtUserName.SetFocus
Else
txtSQL = "select * from user_Info where user_ID = '" & Trim(txtUserName.Text) & "'"
Set mrc = ExecuteSQL(txtSQL, MsgText)


If mrc.EOF 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 = ""
Exit Sub
End If
End If
End If

miCount = miCount + 1
If miCount = 3 Then
Me.Hide
End If
Exit Sub
End Sub

...全文
181 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
kingjin88 2009-07-29
  • 打赏
  • 举报
回复
结了吗 啊
我是一道光_ 2009-07-24
  • 打赏
  • 举报
回复



结贴
the_fire 2009-07-24
  • 打赏
  • 举报
回复



语法

Str(number)




貌似trim和trim$差不多一样
the_fire 2009-07-24
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 lfsfxy9 的回复:]
rst.Open Trim(Str(SQL)), cnn, adOpenKeyset, adLockOptimistic
[/Quote]
Trim$(sql)就行了
还有就是你那个sub main里的东西,也错了。我帮你改了,你记得看看。
有困难就找哥,
我是一道光_ 2009-07-24
  • 打赏
  • 举报
回复
原因出在了 frmLogin 这个地方,拼写错误了...


马虎不得呀~

呵呵,结贴啦
sdhdy 2009-07-23
  • 打赏
  • 举报
回复
'try
If mrc.EOF or mrc.bof Then
Zoezs 2009-07-23
  • 打赏
  • 举报
回复

strConnect = "DRIVER=SQL Server;UID=sa;PWD=sa;DATABASE=DBNAME;SERVER=192.168.0.1"
conn.ConnectionString = strConnect '设置连接字串
conn.CursorLocation = adUseClient

strSql = "select top 10 * from TB"

conn.Open strConnect
Set rs = conn.Execute(strSql)'执行语句
Zoezs 2009-07-23
  • 打赏
  • 举报
回复

strConnect = "DRIVER=SQL Server;UID=sa;PWD=sa;DATABASE=DBNAME;SERVER=192.168.0.1"
conn.ConnectionString = strConnect '设置连接字串
conn.CursorLocation = adUseClient

strSql = "select top 10 * from TB"

conn.Open strConnect
Set rs = conn.Execute(strSql)'执行语句
Zoezs 2009-07-23
  • 打赏
  • 举报
回复
你的ExecuteSQL是什么样的啊?
我是一道光_ 2009-07-23
  • 打赏
  • 举报
回复





chowyi 2009-07-23
  • 打赏
  • 举报
回复
不懂vb
我是一道光_ 2009-07-23
  • 打赏
  • 举报
回复
sdhdy 你好哈

经过我的try ,VB环境 把 后面的那个 eof 直接改成 EOF了,还是不行

不知道为什么....

后来的朋友可否将出现这种情况的肯能小小的列举一下呢,不胜感激~
我是一道光_ 2009-07-23
  • 打赏
  • 举报
回复
ExecuteSQL 函数如下 :





Public Function ConnectString() _
As String
'returns a DB ConnectString
ConnectString = "FileDSN=student.dsn;UID=sa;PWD=123"
End Function

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(Str(SQL)), cnn, adOpenKeyset, adLockOptimistic

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
Option Explicit
Public txtSQL As String
Dim mrc As adodb.Recordset
'用户的读写权限标识
Dim mintRW As Integer
'状态条中显示的时间信息
Public msBarText As String
Public reportSQL As String
Public Sub RecordFind()
'
End Sub
Public Sub RecordRefresh()

'显示数据
msBarText = "当前数据时间范围:" & Format(DateAdd("m", -1, Now), "yyyy-mm-dd") & "至" & Format(Now, "yyyy-mm-dd")

ShowData
End Sub


Public Sub RecordAdd()
gintCKSmode = ADD
frmCKSetup1.Show 1
'ShowData
End Sub


'删除记录
Public Sub RecordDelete()
Dim sSQL As String
Dim intCount As Integer
Dim recTemp As adodb.Recordset
Dim MsgText As String


On Error GoTo myErr

If msgList.Rows > 1 Then
If MsgBox("真的要删除仓库编号为" & Trim(msgList.TextMatrix(msgList.Row, 1)) & "的记录吗?", vbOKCancel + vbExclamation, "警告") = vbOK Then
intCount = msgList.Row

sSQL = "select * from inh full join outh on inh.ckdm = outh.ckdm full join kucun on inh.ckdm =kucun.ckdm full join zc zc1 on zc1.i_ckdm = inh.ckdm full join zc zc2 on zc2.o_ckdm = inh.ckdm where "
sSQL = sSQL & "inh.ckdm = '" & Trim(msgList.TextMatrix(intCount, 1)) & "'"
sSQL = sSQL & "or outh.ckdm = '" & Trim(msgList.TextMatrix(intCount, 1)) & "'"
sSQL = sSQL & "or kucun.ckdm = '" & Trim(msgList.TextMatrix(intCount, 1)) & "'"
sSQL = sSQL & "or zc1.i_ckdm = '" & Trim(msgList.TextMatrix(intCount, 1)) & "'"
sSQL = sSQL & "or zc2.o_ckdm = '" & Trim(msgList.TextMatrix(intCount, 1)) & "'"

Set recTemp = ExecuteSQL(sSQL, MsgText)
If Not recTemp.EOF Then
MsgBox "数据库中存在与" & Trim(msgList.TextMatrix(intCount, 2)) & "相关的纪录,不能删除!", vbOKOnly, "警告"
Exit Sub
Else
sSQL = "delete from dm_ck where dm ='" & Trim(msgList.TextMatrix(intCount, 1)) & "'"
Set recTemp = ExecuteSQL(sSQL, MsgText)
End If

'Unload frmCKSetup
'frmCKSetup.txtSQL = "select * from dm_ck"
'frmCKSetup.Show
ShowData
End If
End If

Exit Sub

myErr:
ShowError
End Sub

Public Sub RecordEdit()
Dim intCount As Integer

If msgList.Rows > 1 Then
gintCKSmode = EDIT
intCount = msgList.Row
If intCount > 0 Then
frmCKSetup1.txtSQL = "select * from dm_ck where dm ='" & Trim(msgList.TextMatrix(intCount, 1)) & "'"
frmCKSetup1.Show 1
Else
MsgBox "警告", vbOKOnly + vbExclamation, "请首先选择需要修改的纪录!"
End If
ShowData
Else
Call RecordAdd
End If
End Sub


Private Sub Form_Activate()
'设置读写权限
SetWorkRW mintRW
fMainForm.sbStatusBar.Panels(1).Text = msBarText
End Sub

Private Sub Form_Load()
'用户操作权限
Dim sPermission As String
Dim recTemp As Recordset
Dim sSQL As String
Dim sByte As String
Dim MsgText As String

On Error GoTo myErr
'设置操作的表名称
'msTableName = "ampaytune"
'msRptName = "paytune.rpt"
'msOrderBy = " order by tzdate,tzid"
'sOrder0 = "+ {tzdate}"
'sOrder1 = "+ {tzid}"
'msSelect = "select * from "

'置mintRW初值
mintRW = 0
sSQL = "select rw from permission where module=10 and id='" & sUserName & " '"
Set recTemp = ExecuteSQL(sSQL, MsgText)
If recTemp.EOF = False Then
mintRW = CInt(recTemp!rw)
Else
mintRW = ERRORMODE
SetMdiEnv
MsgBox "您的帐号权限有错误!", vbOKOnly + vbCritical, "错误"
Exit Sub
End If



'设置msSql
'msSql = msSelect & msTableName & " where tzdate>='" & Format(DateAdd("m", -1, Now), "yyyy-mm-dd") & "' and tzdate<='" & Format(Now, "yyyy-mm-dd") & "'" & msOrderBy

'显示数据
msBarText = "当前数据时间范围:" & Format(DateAdd("m", -1, Now), "yyyy-mm-dd") & "至" & Format(Now, "yyyy-mm-dd")
ShowTitle
ShowData

Set recTemp = Nothing
Exit Sub

myErr:
ShowError






End Sub

Private Sub Form_Resize()
If Me.WindowState <> vbMinimized And fMainForm.WindowState <> vbMinimized Then
'边界处理
If Me.ScaleHeight < 10 * lblTitle.Height Then

Exit Sub
End If
If Me.ScaleWidth < lblTitle.Width + lblTitle.Width / 2 Then

Exit Sub
End If
'控制控件的位置

lblTitle.Top = lblTitle.Height
lblTitle.Left = (Me.Width - lblTitle.Width) / 2

msgList.Top = lblTitle.Top + lblTitle.Height + lblTitle.Height / 2
msgList.Width = Me.ScaleWidth - 200
msgList.Left = Me.ScaleLeft + 100
msgList.Height = Me.ScaleHeight - msgList.Top

End If
End Sub



Public Sub FormClose()
Unload Me
End Sub
Private Sub ShowData()

Dim j As Integer
Dim i As Integer
Dim MsgText As String

On Error GoTo myErr


Set mrc = ExecuteSQL(txtSQL, MsgText)
With msgList
.Rows = 1

Do While Not mrc.EOF
.Rows = .Rows + 1
For i = 1 To mrc.Fields.Count
If Not IsNull(Trim(mrc.Fields(i - 1))) Then
Select Case mrc.Fields(i - 1).Type
Case adDBDate
.TextMatrix(.Rows - 1, i) = Format(mrc.Fields(i - 1) & "", "yyyy-mm-dd")
Case Else
.TextMatrix(.Rows - 1, i) = mrc.Fields(i - 1) & ""
End Select
End If
Next i
mrc.MoveNext
Loop


End With


fMainForm.sbStatusBar.Panels(1).Text = msBarText
Set mrc = Nothing
Exit Sub

myErr:
ShowError


End Sub


'显示Grid表头
Private Sub ShowTitle()
Dim i As Integer

With msgList
.Cols = 4
.TextMatrix(0, 1) = "仓库编号"
.TextMatrix(0, 2) = "仓库名称"
.TextMatrix(0, 3) = "备注信息"

'固定表头
.FixedRows = 1

'设置各列的对齐方式
For i = 0 To 3
.ColAlignment(i) = 0
Next i


'表头项居中
.FillStyle = flexFillRepeat
.Col = 0
.Row = 0
.RowSel = 1
.ColSel = .Cols - 1
.CellAlignment = 4

'设置单元大小
.ColWidth(0) = 1000
.ColWidth(1) = 1000
.ColWidth(2) = 2000
.ColWidth(3) = 3000
.Row = 1

End With
End Sub




Private Sub Form_Unload(Cancel As Integer)
SetMdiEnv
End Sub

Private Sub msgList_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
'右键弹出
If Button = 2 And Shift = 0 Then

End If

End Sub


在该网站的上传权限,但不允许上传违犯国家安全及违犯《中华人民共和国著作权法》等相关法律法规,以及一切色情、病毒、等危害广大用户利益的资源。同时要遵守CSDN下载社区上传规则,如一经发现或收到举报我社区有权删除,并将扣除上传者在下载社区的全部积分,而因此带来的一切后果由上传者自负。

34,873

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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