Private Sub modifySure_Click()
Dim rs As New ADODB.Recordset
Dim rs2 As New ADODB.Recordset
Dim sql As String
Dim sql2 As String If Trim(username.Text = "") Then
MsgBox "没有输入用户名,请重新输入!", vbOKOnly + vbExclamation, "警告" '弹出的对话框中只有一个确定按钮和一个警告的图标
username.SetFocus
sql = "select * from user_info where user = '" & username.Text & "'and pw = '" & oldPw.Text & "'"
Set rs = TransactSQL(sql)
Else
If rs.EOF = True Then
MsgBox "用户密码不匹配,无权更改!", vbOKOnly + vbExclamation, "警告"
username.SetFocus
Else
If newPw1.Text <> newPw2.Text Then
MsgBox "两次输入密码不一致!", vbOKOnly
Else
sql2 = "update user_info set pw = '" & newPw1.Text & "' where user = '" & username.Text & "'"
sql2 = "select * from user_info where user ='" & username.Text & "'"
Set rs2 = TransactSQL(sql)
rs2.Fields(1) = newPw1.Text
rs2.Update
rs2.Close
MsgBox "密码修改成功!", vbOKOnly, "修改密码"
Me.Hide
End If
End If
End If
End Sub
这是一个修改密码的窗体代码,每次运行到if rs.eof=true then这句的时候就会弹出错误提示,请问各位老师这是什么原因,该怎么修改呢?谢谢了!也许这里面还有很多错误,我是新手,麻烦各位了
Dim rs As New ADODB.Recordset
Dim rs2 As New ADODB.Recordset
Dim sql As String
Dim sql2 As String If Trim(username.Text = "") Then
MsgBox "没有输入用户名,请重新输入!", vbOKOnly + vbExclamation, "警告" '弹出的对话框中只有一个确定按钮和一个警告的图标
username.SetFocus
sql = "select * from user_info where user = '" & username.Text & "'and pw = '" & oldPw.Text & "'"
Set rs = TransactSQL(sql)
Else
If rs.EOF = True Then
MsgBox "用户密码不匹配,无权更改!", vbOKOnly + vbExclamation, "警告"
username.SetFocus
Else
If newPw1.Text <> newPw2.Text Then
MsgBox "两次输入密码不一致!", vbOKOnly
Else
sql2 = "update user_info set pw = '" & newPw1.Text & "' where user = '" & username.Text & "'"
sql2 = "select * from user_info where user ='" & username.Text & "'"
Set rs2 = TransactSQL(sql)
rs2.Fields(1) = newPw1.Text
rs2.Update
rs2.Close
MsgBox "密码修改成功!", vbOKOnly, "修改密码"
Me.Hide
End If
End If
End If
End Sub
这是一个修改密码的窗体代码,每次运行到if rs.eof=true then这句的时候就会弹出错误提示,请问各位老师这是什么原因,该怎么修改呢?谢谢了!也许这里面还有很多错误,我是新手,麻烦各位了
解决方案 »
- 设计一个应用程序,是VB.6连接ACCESS2000数据库,有人帮我弄一个吗?
- VB下可以写在VC下调用的DLL吗?
- 如何在运行时,拖动改变listview的列头的前后顺序??
- 在VB中要实现像Windows优化大师那样的界面怎么做!
- 怎样实现用sendkeys发送键盘按键命令?
- 这里有vc,vb,java,delphi源代码大全,国内和国外的经典软件代码请访问www.feidu.net
- 如何用VB指定一个邮址自动收取网上的mail 你要多少分?都给你要求 要有源码!
- 谁敢进来?
- 请问高手如何用VB编的软件修改注册表而且不需要重新启动计算机呀!希望知道的高手能把代码贴出来谢谢您了!·
- Excel导入Sql Server2000
- 有办法取得这个图版吗?
- 帮忙看看怎么可以读取的到这个网址的网页数据?
Public Function TransactSQL(ByVal sql As String) As ADODB.Recordset '执行SQL语句,并返回记录集对象
Dim cont As ADODB.Connection '声明一个连接
Dim rs As ADODB.Recordset '声明一个数据集对象
Dim strConnection As String
Dim strArray() As String
Set cont = New ADODB.Connection '创建连接
Set rs = New ADODB.Recordset
On Error GoTo transactsql_error '异常处理
strConnection = "provider = microsoft.jet.oledb.4.0;data source = " & App.Path & "\magazineMIS.mdb" '返回一个数据库连接
strArray = Split(sql) '用split函数产生一个包含各个子串的数组
cont.Open strConnection '打开连接
If StrComp(UCase$(strArray(0)), "select", vbTextCompare) = 0 Then
rs.Open Trim$(sql), cont, adOpenKeyset, adLockOptimistic
Set TransactSQL = rs '返回记录集对象
iflag = 1
Else
cont.Execute sql '执行查询语句
iflag = 1
End If
transactsql_exit:
Set rs = Nothing
Set cont = Nothing
Exit Function
transactsql_error:
MsgBox "查询错误:" & Err.Description
iflag = 2
Resume transactsql_exit
End Function
Set rs = TransactSQL(sql)
Else改成 Else
sql = "select * from user_info where user = '" & username.Text & "'and pw = '" & oldPw.Text & "'"
Set rs = TransactSQL(sql)
改一下
sql = "select * from user_info where user = '" & trim(username.Text) & "'and pw = '" & (oldPw.Text)) & "'"
此外你也可以把“If rs.EOF = True Then”改一下if rs.recordcount=0 then
再试试,如果还不行.....我还认为是传进去的sql语句有问题,好好检查一下字段的名称是否拼错?
sql = "select * from user_info where user = '" & trim(username.Text) & "'and pw = '" & trim(oldPw.Text) & "'"