VB中关于Recordset.update 的问题。求教!

代码如下。简单描述一下,功能是修改密码用的,在password表中,一个帐号存在多条记录,密码是相同的,修改密码的话会同时更新该帐号所有的记录。问题是这样的:执行上面的程... 代码如下。简单描述一下,功能是修改密码用的,在password 表中,一个帐号存在多条记录,密码是相同的,修改密码的话会同时更新该帐号所有的记录。
问题是这样的:执行上面的程序,数据库中的记录没有被更新。程序也不报错。
Private Sub cmdOK_Click()
Dim strSQL As String
Dim rst As ADODB.Recordset
frmLogin.MousePointer = 11
strSQL = "select * from password where password001 = '" & txtUserID.Text & "'"
Set rst = CreateRecordset(conn, strSQL)
If Err.Number <> 0 Then
frmLogin.MousePointer = 0
MsgBox "修改密码时,开启数据库失败!" & Chr(13) & "错误描述:" & Err.Description
Exit Sub
End If
If rst.RecordCount > 0 Then
rst.MoveFirst
While Not rst.EOF

' MsgBox rst.Fields("password002").Value
If rst.Fields("password002").Value = txtOPassword.Text Then
If txtNPassword1.Text = txtNPassword2.Text Then
rst.Fields("password002").Value = txtNPassword1.Text
Else
frmLogin.MousePointer = 0
MsgBox "请确认新密码是否相同!!!", 48, "警告"
Exit Sub
End If
Else
frmLogin.MousePointer = 0
MsgBox "密码错误!!!" & Chr(13) & "请注意大小写!!!", 48, "警告"
Exit Sub
End If
rst.MoveNext
Wend
rst.UpdateBatch
Else
frmLogin.MousePointer = 0
MsgBox "系统内没有你的帐号!!!", 48, "警告"
Exit Sub
End If

frmLogin.MousePointer = 0

MsgBox "更新成功!!!", 48, "提示"
frmEditPassword.Hide
frmMain.Show
End Sub

Public Function CreateRecordset(ByRef aConn As ADODB.Connection, ByVal aSQLString As String) As ADODB.Recordset
On Error GoTo suberrhdl
Dim theRecordSet As ADODB.Recordset
If UCase(Trim(TypeName(aConn))) <> "CONNECTION" Then
Exit Function
End If
Set theRecordSet = New ADODB.Recordset
theRecordSet.CursorLocation = adUseClient
Set theRecordSet.ActiveConnection = aConn
' theRecordSet.CursorType = adOpenStatic
theRecordSet.CursorType = adUseClient
' theRecordSet.LockType = adLockPessimistic
theRecordSet.LockType = adLockBatchOptimistic
theRecordSet.Source = aSQLString
theRecordSet.Open
Set theRecordSet.ActiveConnection = Nothing
Set CreateRecordset = theRecordSet
Exit Function
suberrhdl:
If Not aConn Is Nothing Then
Set aConn = Nothing
End If
End Function
当我这样写道时候就可以更新
Dim rst As New ADODB.Recordset
frmLogin.MousePointer = 11
strSQL = "select * from cppassword where cppassword001 = '" & txtUserID.Text & "'"
‘ Set rst = CreateRecordset(conn, strSQL)
rst.Open strSQL, conn, 3, 4, adCmdText
但这个程序并不是只有这个功能,其他功能也会UPDATE,会调用到CreateRecordset这个方法
展开
 我来答
百度网友c01acee
2011-07-26 · TA获得超过187个赞
知道小有建树答主
回答量:587
采纳率:0%
帮助的人:380万
展开全部
strSQL = "select * from password where password001 = '" & txtUserID.Text & "'"

Passwork001 = txtuserid????? 我理解错误你就是这么设定的?还是???
追问
首先,谢谢你的回答,
然后,SQL语句没问题,
再然后,我还真没看懂你的Passwork001 = txtuserid?????是要表达什么意思。
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式