注册 登录
编程论坛 VB6论坛

一新人 纠结我好久的问题 那位帮帮忙

wbzjacky 发布于 2012-12-01 17:11, 410 次点击
提示错误3704 对象关闭时不允许操作

这到底是那错了


Public username As String
Public userpower As String
Public myconnection As New ADODB.Connection



Dim txtsql As String
Public n As Integer
Private Sub Command1_Click()
Dim txtsql As String
Dim Msgtext As String
Dim rsd1 As ADODB.Recordset
Dim rsd2 As ADODB.Recordset

username = ""
If Trim(txtid.Text = "") Then
MsgBox "用户名不能为空,请重新输入!", vbOKOnly + vbExclamation, "警告"
txtid.SetFocus
Else
txtsql = "select * from 用户表 where 用户名=" '&txtid.text&'""
Set rsd1 = myconnection.Execute(txtsql)
If rsd1.EOF Then
    MsgBox "没有这个用户,请重新输入用户名!", vbOKOnly + vbExclamation, "警告"
    txtid.Text = ""
    txtpwd.Text = ""
    txtid.SetFocus
Else
     username = Trim(txtid.Text)
     txtsql = "select 口令,权限 from 用户表 where 用户名=" '&username&'""
     Set rsd2 = myconnection.Execute(txtsql)
     If Trim(rsd2.Fields(0)) = Trim(txtpwd.Text) Then
       userpower = rsd2.Fields(1)
       rsd2.Close
       Unload Me
       主窗体.Show
       myconnection.Close
       Else
       MsgBox "输入密码不正确,请重新输入!", vbOKOnly + vbExclamation, "警告"
       txtpwd.Text = ""
       txtpwd.SetFocus
       End If
       End If
       End If
       n = n + 1
       If n > 3 Then
       MsgBox "操作次数过了三次"
       Unload Me
       myconnection.Close
       End If
      
End Sub

Private Sub Command2_Click()
Unload Me
End Sub

Private Sub Form_Load()
myconnection.ConnectionString = "driver={sql server};server=chh;uid=sa;pwd=111;database=学生信息管理"
myconnection.Open
n = 0
End Sub


4 回复
#2
ts_liangkun2012-12-01 21:24
ADODB.Recordset 每次应用的时候要重新初始化,要不然就出现你的错误
#3
ts_liangkun2012-12-01 21:26
刚才说错了,我又看了看,这个问题就是你看看可能是在操作表的时候 myconnection 你关闭了,等你再应用的时候这个链接没有了
#4
newOwen2012-12-02 20:08
同是新人,看到一些语法问题
1. If Trim(txtid.Text = "") Then --> If Trim(txtid.Text) = "" Then
2. txtsql = "select * from 用户表 where 用户名=" '&txtid.text&'""  --> txtsql = "select * from 用户表 where 用户名= '" &txtid.text&"'"
......
#5
wbzjacky2012-12-03 09:27
谢谢了 原来是这个  '" &txtid.text&"'" 标点的问题
1