| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 3094 人关注过本帖
标题:提示:对象关闭时,不允许操作
取消只看楼主 加入收藏
hengxinying
Rank: 1
来 自:湖南
等 级:新手上路
帖 子:45
专家分:0
注 册:2009-3-12
结帖率:100%
收藏
 问题点数:0 回复次数:1 
提示:对象关闭时,不允许操作
VB中怎么用代码把记录添加到数据库中去?我的代码一老报错,提示:对象关闭时,不允许操作。。。。我用的是sq server2000
搜索更多相关主题的帖子: 对象 提示 
2010-03-31 12:55
hengxinying
Rank: 1
来 自:湖南
等 级:新手上路
帖 子:45
专家分:0
注 册:2009-3-12
收藏
得分:0 
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
这是代码。。。
2010-04-04 14:19
快速回复:提示:对象关闭时,不允许操作
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.017141 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved