利用VB修改数据库中的密码(高分求解)

beyondsoftandy 2010-11-26 08:42:36
各位高手,我是初学者,写了个程序来修改数据库中某个表中的密码,但是总是不成功,总在mrc.Fields(1) = Text2.Text
mrc.Update
mrc.close
这三句报错,谁能帮我看看呀?谢谢啦!
代码如下:
Dim txtSQL, MsgText As String
Dim mrc As ADODB.Recordset
Dim rs As Boolean
rs = True
If Text2.Text = "" Then
MsgBox "密码不能为空! 请输入密码!", vbOKOnly + vbExclamation, "警告"
rs = False
Text2.Text = ""
Text3.Text = ""
Text2.SetFocus
Exit Sub
End If

If Trim(Text2.Text) <> Trim(Text3.Text) Then
MsgBox "密码输入不正确!", vbOKOnly + vbExclamation, "警告"
Text2.SetFocus

Text2.Text = ""
Text3.Text = ""
Else
txtSQL = "update userinfo set password='" & Text2.Text & "' where uid= '" & username & "'"

Set mrc = ExecuteSQL(txtSQL, MsgText)
mrc.Fields(1) = Text2.Text
mrc.Update
mrc.close



MsgBox "密码修改成功!", vbOKOnly + vbExclamation, "修改密码"
Me.Hide

End If
...全文
173 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
XYRGASYX 2010-11-26
  • 打赏
  • 举报
回复
学习学习学习...
beyondsoftandy 2010-11-26
  • 打赏
  • 举报
回复
exceutesql是我提前定义的功能模块中的
Public gintMode As Integer
Public flagEdit As Boolean
Public UserName As String



Sub Main()
login.Show
End Sub

Public Function ConnectString() _
As String
'returns a DB ConnectString
ConnectString = "Provider=SQLOLEDB.1;" & _
"Persist Security Info=False;" & _
"UID=sa;PWD=zzq=1861;" & _
"Initial Catalog=HRMIS;" & _
"Data Source=(local)"
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
'将enter换成tab
Public Sub EnterToTab(Keyasc As Integer)
If Keyasc = 13 Then
SendKeys "{TAB}"
End If
End Sub
dbcontrols 2010-11-26
  • 打赏
  • 举报
回复
ExecuteSQL是啥你没说,神仙也治不得
lxq19851204 2010-11-26
  • 打赏
  • 举报
回复
是你的数据库连接问题
beyondsoftandy 2010-11-26
  • 打赏
  • 举报
回复
我的数据库表中的id是uid,改成mrc.Fields("uid") = Text2.Text,依然报错
dbcontrols 2010-11-26
  • 打赏
  • 举报
回复
可以用编号
[Quote=引用 2 楼 luofenghen 的回复:]
mrc.Fields(1) = Text2.Text
1要改成字段吧?
比如 "ID"
[/Quote]
luofenghen 2010-11-26
  • 打赏
  • 举报
回复
mrc.Fields(1) = Text2.Text
1要改成字段吧?
比如 "ID"
lxq19851204 2010-11-26
  • 打赏
  • 举报
回复
把工程传给我看下吧.qq:280561935

1,216

社区成员

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

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