提示:对象关闭时,不允许操作
VB中怎么用代码把记录添加到数据库中去?我的代码一老报错,提示:对象关闭时,不允许操作。。。。我用的是sq server2000
Dim objRS As ADODB.Recordset
Dim objConn As ADODB.Connection
Private Sub Command1_Click()
If opp = "add" Then
If Text1.Text = "" Then
MsgBox ("请输入客户姓名")
Text1.SetFocus
ElseIf Text2.Text = "" Then
MsgBox ("请输入客户性别")
Text2.SetFocus
ElseIf Text3.Text = "" Then
MsgBox ("请输入客户电话")
Text3.SetFocus
ElseIf Text4.Text = "" Then
MsgBox ("请输入客户E_mail")
Text4.SetFocus
ElseIf Text5.Text = "" Then
MsgBox ("请输入购车型号")
Text5.SetFocus
ElseIf Text6.Text = "" Then
MsgBox ("请输入购车价格")
Text6.SetFocus
ElseIf Text7.Text = "" Then
MsgBox ("请输入身份证号")
Text7.SetFocus
ElseIf Text8.Text = "" Then
MsgBox ("请输入客户通讯地址")
Text8.SetFocus
Else
Set objRS = New ADODB.Recordset
con = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=carsale;Data Source=YANHENGYING"
Set objConn = New ADODB.Connection
objConn.Open con
objRS.Open "select * from cusmessage where name='" & Text1.Text & "'", con, adOpenKeyset
If objRS.RecordCount = 0 Then
objRS.AddNew ‘在这里一老出错
objRS("name") = Text1.Text
objRS("sex") = Text2.Text
objRS("tel") = Text3.Text
objRS("E_mail") = Text4.Text
objRS("sale_type") = Text5.Text
objRS("sale_price") = Text6.Text
objRS("ID") = Text7.Text
objRS("address") = Text8.Text
objRS.Update
MsgBox ("添加成功!!")
editcusmessage.Show
Unload Me
Else
MsgBox "该客户已存在!", , "提示信息"
editcus.Text1.Text = ""
editcus.Text2.Text = ""
editcus.Text3.Text = ""
editcus.Text4.Text = ""
editcus.Text5.Text = ""
editcus.Text6.Text = ""
editcus.Text7.Text = ""
editcus.Text8.Text = ""
End If
End If
End If
End Sub
这是代码。。。