VB 对象打开时不允许操作:错误3705
PublicrsAsNewADODB.RecordsetPublicconnAsNewADODB.ConnectionPublicFunctionsq()AsString...
Public rs As New ADODB.Recordset
Public conn As New ADODB.Connection
Public Function sq() As String
conn.ConnectionString = "Driver={sql server};server=" & Trim(Text1.Text) & ";uid=sa;pwd=;database=" & Trim(zt.Text) & ""
End Function
Private Sub Command1_Click()
Call sq
conn.Open
If rs.State = adStateOpen Then rs.Close
rs.Open "select 用户名,密码 from login where 用户名='" & Trim(Text2.Text) & "' And 密码='" & Trim(Text3.Text) & "'", conn, adOpenStatic, adLockReadOnly, adCmdText
If rs.EOF = True And rs.BOF Then
m = MsgBox("请重新登录", vbExclamation)
Text2.Text = ""
Text2.SetFocus
ElseIf ch1.Value = 1 Then
modify.Show
Unload Me
Else
Form1.Show
Unload Me
End If
rs.Close
Set rs = Nothing
End Sub
Private Sub Command2_Click()
Unload Me
End Sub
Public Function usermodify() As String
Call sq
conn.Open
If rs.State = adStateOpen Then rs.Close
Set rs = Nothing
If Trim(modify.newp.Text) = Trim(modify.rnewp.Text) Then
rs.Open "update login set 密码 = '" & Trim(modify.newp.Text) & "' where 用户名='" & Trim(modify.oldp.Text) & "'"
rs.Update
MsgBox "密码修改成功", vbExclamation
Else
MsgBox "两次输入密码不一至,请得新输入", , 重置密码
End If
rs.Close
Set rs = Nothing
End Function
在调用执行usermodify时提示的 展开
Public conn As New ADODB.Connection
Public Function sq() As String
conn.ConnectionString = "Driver={sql server};server=" & Trim(Text1.Text) & ";uid=sa;pwd=;database=" & Trim(zt.Text) & ""
End Function
Private Sub Command1_Click()
Call sq
conn.Open
If rs.State = adStateOpen Then rs.Close
rs.Open "select 用户名,密码 from login where 用户名='" & Trim(Text2.Text) & "' And 密码='" & Trim(Text3.Text) & "'", conn, adOpenStatic, adLockReadOnly, adCmdText
If rs.EOF = True And rs.BOF Then
m = MsgBox("请重新登录", vbExclamation)
Text2.Text = ""
Text2.SetFocus
ElseIf ch1.Value = 1 Then
modify.Show
Unload Me
Else
Form1.Show
Unload Me
End If
rs.Close
Set rs = Nothing
End Sub
Private Sub Command2_Click()
Unload Me
End Sub
Public Function usermodify() As String
Call sq
conn.Open
If rs.State = adStateOpen Then rs.Close
Set rs = Nothing
If Trim(modify.newp.Text) = Trim(modify.rnewp.Text) Then
rs.Open "update login set 密码 = '" & Trim(modify.newp.Text) & "' where 用户名='" & Trim(modify.oldp.Text) & "'"
rs.Update
MsgBox "密码修改成功", vbExclamation
Else
MsgBox "两次输入密码不一至,请得新输入", , 重置密码
End If
rs.Close
Set rs = Nothing
End Function
在调用执行usermodify时提示的 展开
4个回答
展开全部
楼上的不懂不要误导人家,明明是操作SQL SERVER的一段代码。 楼主的错误在于 Command1_Click()事件中 还有 usermodify() 函数中 都调用了
Call sq
conn.Open
这里conn应该是一个全局或者模块级别的数据库连接对象,只需要open一次就可以了。其他使用这个conn对象的recordset直接就可以通过它来连接,操作数据库了。
你点击command1之后,
usermodify()里面就不用
Call sq
conn.Open
这两句了。
当然从整体结构来看你的代码这样写不是很合理,如果只是用来做个练习也就罢了。
Call sq
conn.Open
这里conn应该是一个全局或者模块级别的数据库连接对象,只需要open一次就可以了。其他使用这个conn对象的recordset直接就可以通过它来连接,操作数据库了。
你点击command1之后,
usermodify()里面就不用
Call sq
conn.Open
这两句了。
当然从整体结构来看你的代码这样写不是很合理,如果只是用来做个练习也就罢了。
展开全部
Public rs As New ADODB.Recordset
Public conn As New ADODB.Connection
Public Function sq() As String
conn.ConnectionString = "Driver={sql server};server=" & Trim(Text1.Text) & ";uid=sa;pwd=;database=" & Trim(zt.Text) & ""
End Function
Private Sub Command1_Click()
Call sq
conn.Open
If rs.State = adStateOpen Then rs.Close
rs.Open "select 用户名,密码 from login where 用户名='" & Trim(Text2.Text) & "' And 密码='" & Trim(Text3.Text) & "'", conn, adOpenStatic, adLockReadOnly, adCmdText
If rs.EOF = True And rs.BOF Then
m = MsgBox("请重新登录", vbExclamation)
Text2.Text = ""
Text2.SetFocus
ElseIf ch1.Value = 1 Then
modify.Show
Unload Me
Else
Form1.Show
Unload Me
End If
rs.Close
Set rs = Nothing
conn.Close '增加关闭对象
Set conn = NotHing '增加关闭对象
End Sub
Private Sub Command2_Click()
Unload Me
End Sub
Public Function usermodify() As String
Call sq
conn.Open
If rs.State = adStateOpen Then rs.Close
Set rs = Nothing
If Trim(modify.newp.Text) = Trim(modify.rnewp.Text) Then
rs.Open "update login set 密码 = '" & Trim(modify.newp.Text) & "' where 用户名='" & Trim(modify.oldp.Text) & "'"
rs.Update
MsgBox "密码修改成功", vbExclamation
Else
MsgBox "两次输入密码不一至,请得新输入", , 重置密码
End If
rs.Close
Set rs = Nothing
conn.Close '增加关闭对象
Set conn = NotHing '增加关闭对象
End Function
Public conn As New ADODB.Connection
Public Function sq() As String
conn.ConnectionString = "Driver={sql server};server=" & Trim(Text1.Text) & ";uid=sa;pwd=;database=" & Trim(zt.Text) & ""
End Function
Private Sub Command1_Click()
Call sq
conn.Open
If rs.State = adStateOpen Then rs.Close
rs.Open "select 用户名,密码 from login where 用户名='" & Trim(Text2.Text) & "' And 密码='" & Trim(Text3.Text) & "'", conn, adOpenStatic, adLockReadOnly, adCmdText
If rs.EOF = True And rs.BOF Then
m = MsgBox("请重新登录", vbExclamation)
Text2.Text = ""
Text2.SetFocus
ElseIf ch1.Value = 1 Then
modify.Show
Unload Me
Else
Form1.Show
Unload Me
End If
rs.Close
Set rs = Nothing
conn.Close '增加关闭对象
Set conn = NotHing '增加关闭对象
End Sub
Private Sub Command2_Click()
Unload Me
End Sub
Public Function usermodify() As String
Call sq
conn.Open
If rs.State = adStateOpen Then rs.Close
Set rs = Nothing
If Trim(modify.newp.Text) = Trim(modify.rnewp.Text) Then
rs.Open "update login set 密码 = '" & Trim(modify.newp.Text) & "' where 用户名='" & Trim(modify.oldp.Text) & "'"
rs.Update
MsgBox "密码修改成功", vbExclamation
Else
MsgBox "两次输入密码不一至,请得新输入", , 重置密码
End If
rs.Close
Set rs = Nothing
conn.Close '增加关闭对象
Set conn = NotHing '增加关闭对象
End Function
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Command1_Click()
usermodify()
均调用了下两个函数
Call sq
conn.Open
usermodify()
均调用了下两个函数
Call sq
conn.Open
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
目测是从txt文件中读取密码那啥的
你的txt文件是否放在了指定文件夹
用的什么系统呢?Windows7?WinVista?WindowsXP?
你的txt文件是否放在了指定文件夹
用的什么系统呢?Windows7?WinVista?WindowsXP?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询