出错提示 Adodc1 对像关闭时,不允许操作
出错提示 " Adodc1 对像关闭时,不允许操作 "
光标会指向这句
"Adodc1.Refresh "
Function aa(user As String, pwd As String) As Boolean
Adodc1.RecordSource = "insert into username values( ' " + user + " ', ' " + pwd + " ') " '把申请的用户名和密码添加到数据库里
Adodc1.Refresh
On Error Resume Next
Adodc2.RecordSource = "select * from username where 用户名= ' " + user + " ' and 密码= ' " + pwd + " ' " '确定一下数据库里是否添加了要申请的用户名和密码
Adodc2.Refresh
On Error Resume Next
If Adodc2.Recordset.RecordCount = 1 Then
aa = True
Else
aa = False
End If
End Function
Private Sub Command1_Click()
Text1.Text = " "
Text2.Text = " "
Text3.Text = " "
Text1.SetFocus
End Sub
Private Sub Command2_Click()
Dim cc As Boolean
Dim users As String
Dim mi As String
If Text1.Text = " " Then
MsgBox "你输入的用户名 "
Else
If Text2.Text = " " Then
MsgBox "你输入密码 "
Else
If Text2.Text = Text3.Text Then '两次输入的密码是否一致
users = Text1.Text
mi = Text2.Text
cc = aa(users, mi)
If cc = True Then
MsgBox "恭喜你注册成功 "
Unload Me
Form1.Show
Else
MsgBox "注册失败 "
Text1.Text = " "
Text2.Text = " "
Text3.Text = " "
Text1.SetFocus
End If
Else
MsgBox "你输入的密码和确认密码不一致 "
End If
End If
End If
End Sub
Private Sub Form_Load()
Adodc1.ConnectionString = cnstr
Adodc2.ConnectionString = cnstr
End Sub
模块代码
Public Function cnstr() As String
cnstr = "provider=sqloledb;persist security info=false;user id=sa;initial catalog=studentsys "
End Function
Public Function cnn() As ADODB.Connection
Set cnn = New ADODB.Connection
cnn.Open "driver={sql server};server=(local);database=studentsys;uid=sa;pwd= "
End Function
[解决办法]
对数据库的Insert,Update,Delete操作不要写在Recordset里,RecordSource也不行,应该使用ADODB对象库当中的Connection
Dim dCn As New ADODB.Connection
dcn.execute "insert .....