Set recset1 = New ADODB.Recordset
    recset1.Open "insert into tb_input (sn,model,error_code,station,ipt_time,ipt_shift,status,ipt_person) values( """ & sn_txt.Text & """," & mod_cbb.Text & """,""" & errc_cbb.Text & """,""" & stat_cbb.Text & """,""" & intime_lb.Caption & """,""" & inshift_lb.Caption & """,""" & stau_lb.Caption & """,""" & inperson_txt.Text & """)", db_conn
    recset1.Close
不知为什么会出现Runtime Error
open 是不是只能进行查询,因为我用select时没什么问题

解决方案 »

  1.   

    If recset1.State = 1 Then
           recset1.Close
        End If
      

  2.   

    to sxs69() 加入后不行啊!仍然报错,为什么我把OPEN后面的SQL语句换成SELECT就可以了!
    请大家帮帮忙!
      

  3.   

    Set recset1 = New ADODB.Recordset
        recset1.Open "select * from tb_input",db_conn,3,3
        recset1.Open "insert into tb_input (sn,model,error_code,station,ipt_time,ipt_shift,status,ipt_person) values( """ & sn_txt.Text & """," & mod_cbb.Text & """,""" & errc_cbb.Text & """,""" & stat_cbb.Text & """,""" & intime_lb.Caption & """,""" & inshift_lb.Caption & """,""" & stau_lb.Caption & """,""" & inperson_txt.Text & """)", db_conn
        If recset1.State = 1 Then
           recset1.Close
        End If
      

  4.   

    不行,我看 insert 操作是不是要用 execsql才可以啊,不过试了一下好像也不行,DELPHI里不返回结果的就是要用execsql,虽然用open 会出错,但也可以操作成功!
      

  5.   

    抱歉,写错了,这样也可以
    db_conn.Execute "insert into tb_input (sn,model,error_code,station,ipt_time,ipt_shift,status,ipt_person) values( """ & sn_txt.Text & """," & mod_cbb.Text & """,""" & errc_cbb.Text & """,""" & stat_cbb.Text & """,""" & intime_lb.Caption & """,""" & inshift_lb.Caption & """,""" & stau_lb.Caption & """,""" & inperson_txt.Text & """)"
      

  6.   

    Private cmd As ADODB.CommandSet cmd = New ADODB.Command
    cmd.ActiveConnection = conn
    cmd.CommandText = "insert into tb_input (sn,model,error_code,station,ipt_time,ipt_shift,status,ipt_person) values( """ & sn_txt.Text & """," & mod_cbb.Text & """,""" & errc_cbb.Text & """,""" & stat_cbb.Text & """,""" & intime_lb.Caption & """,""" & inshift_lb.Caption & """,""" & stau_lb.Caption & """,""" & inperson_txt.Text & """)"
    cmd.Execute
      

  7.   

    我用的是如下代码:    Dim sql As String
        sql = "insert into tb_input (sn,model,error_code,station,ipt_time,ipt_shift,status,ipt_person) values( """ & sn_txt.Text & """," & mod_cbb.Text & """,""" & errc_cbb.Text & """,""" & stat_cbb.Text & """,""" & intime_lb.Caption & """,""" & inshift_lb.Caption & """,""" & stau_lb.Caption & """,""" & inperson_txt.Text & """)"
        recset1.Open sql, db_conn, adOpenDynamic
    错误提示:
    Run-time error '-2147221503(80040001)'