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这个方法 展开
问题是这样的:执行上面的程序,数据库中的记录没有被更新。程序也不报错。
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这个方法 展开
6个回答
展开全部
strSQL = "select * from password where password001 = '" & txtUserID.Text & "'"
Passwork001 = txtuserid????? 我闹兆悉理猜告解错误你就是这液乎么设定的?还是???
Passwork001 = txtuserid????? 我闹兆悉理猜告解错误你就是这液乎么设定的?还是???
追问
首先,谢谢你的回答,
然后,SQL语句没问题,
再然后,我还真没看懂你的Passwork001 = txtuserid?????是要表达什么意思。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询