当前位置:首页 » 多媒体相关

一个有关ADO的简单代码,请大家帮我修改一下,谢谢!


 
  option   explicit    
  dim   conn   as   new   adodb.connection    
  dim   rs   as   new   adodb.recordset    
  dim   sql   as   string    
   
  private   sub   form_load()    
    dim   connstr   as   string    
    connstr   =   "provider=microsoft.jet.oledb.4.0;data   source=d:\mis\data.mdb"    
    conn.open   connstr    
    rs.cursorlocation   =   aduseclient    
    sql   =   "select   工号,姓名,性别,身份证号码,学历,籍贯,单位编号,职别编号,入厂日期   from   rszd"    
    rs.open   sql,   conn,   adopenkeyset,   adlockpessimistic    
    set   datagrid1.datasource   =   rs    
   
   
  private   sub   cmdfind_click()    
  if   txtname.text=""   then    
    msgbox   "请输入所要查询的名字。",16,"提示"    
    exit   sub    
  else    
    sql   =   "select   工号,姓名,性别,身份证号码,学历,籍贯,单位编号,职别编号,入厂日期   from   rszd   where   姓名="   &   txtname.text   &   ""    
  end   if    
  rs.open   sql,   conn,   adopenkeyset,   adlockpessimistic    
  set   datagrid1.datasource   =   rs    
   
   
  当我运行后点击cmdfind按钮时,系统提示    
  ----------------------    
  实时错误3750:    
  对象打开时操作不被允许。    
  ----------------------    
   
  应当是最后两行有问题,请教如何进行修改呢?

推荐阅读

  • 送Q币 翔升高频73GT DDR3杀599公价 [详细内容]
  • 高盛称盛大已进入下行通道 转型将面临考验 [详细内容]
  • 3250震动模式的BUG [详细内容]
  • 500/1450 影驰80纳米76GE AGP仅999 [详细内容]
  • 微星5535 MP3带您进入新感官时代 [详细内容]
  • N70最新发现的BUG [详细内容]
  • 48条管线超高频 小影霸X19XTX低价 [详细内容]
  • 网友回答:
    网友:lcaaa

    private   sub   cmdfind_click()    
      if   txtname.text=""   then    
        msgbox   "请输入所要查询的名字。",16,"提示"    
        exit   sub    
      else    
          set   rs=nothing  
        sql   =   "select   工号,姓名,性别,身份证号码,学历,籍贯,单位编号,职别编号,入厂日期   from   rszd   where   姓名="   &   txtname.text   &   ""    
      end   if    
      rs.open   sql,   conn,   adopenkeyset,   adlockpessimistic    
      set   datagrid1.datasource   =   rs    
     

    网友:leftie

    在每个rs.open   .....这句之前加一句:if   rs.state=adstateopen   then   rs.close

    网友:x8bits

    你在form_load已经打开过rs,在cmdfind_click中没关闭又再打开rs.你应该在再次打开之前调用rs.close一次

    网友:stonegoldaustin

    locktype  
        recordset对象open方法的locktype参数表示要采用的lock类型,如果忽略这个参数,那么系统会以recordset对象的locktype属性为预设值。locktype参数包含adlockreadonly、adlockprssimistic、adlockoptimistic及adlockbatchoptimistic等,分述如下:  
       
      常数                                     常数值                             说明  
      adlockreadonly                       1                       缺省值,recordset对象以只读方式启动,无法运行addnew、update及delete等方法  
       
      adlockprssimistic                 2                       当数据源正在更新时,系统会暂时锁住其他用户的动作,以保持数据一致性。  
       
      adlockoptimistic                   3                       当数据源正在更新时,系统并不会锁住其他用户的动作,其他用户可以对数据进行增、删、改的操作。  
       
      adlockbatchoptimistic         4                       当数据源正在更新时,其他用户必须将cursorlocation属性改为adudeclientbatch才能对数据进行增、  
                                                                                   删、改的操作。  
       
      因为你在form_load里已经open了一次(但没有关闭,且用的参数会锁住其他用户的操作),所以,你第二次open的时候就出错了.  
       
      请将adlockpessimistic参数改为adlockoptimistic,并且养成好的习惯,及时关闭(释放)无用的资源.

    网友:dreamreality

    private   sub   cmdfind_click()    
      if   txtname.text=""   then    
        msgbox   "请输入所要查询的名字。",16,"提示"    
        exit   sub    
      else    
        sql   =   "select   工号,姓名,性别,身份证号码,学历,籍贯,单位编号,职别编号,入厂日期   from   rszd   where   姓名="   &   txtname.text   &   ""    
      end   if    
      改动过的地方  
      set   rs=new   adodb.recordset  
      改动过的地方  
      rs.open   sql,   conn,   adopenkeyset,   adlockpessimistic    
      set   datagrid1.datasource   =   rs    
     

    网友:ch21st

    不要set   rs=nothing   要close  
      可以这样  
      private   sub   cmdfind_click()    
      if   txtname.text=""   then    
        msgbox   "请输入所要查询的名字。",16,"提示"    
        exit   sub    
      else    
        sql   =   "select   工号,姓名,性别,身份证号码,学历,籍贯,单位编号,职别编号,入厂日期   from   rszd   where   姓名="   &   txtname.text   &   ""    
      end   if    
      ‘-------------增加一句  
          if   rs.state<>0   then   rs.close  
      ’-----------------  
      rs.open   sql,   conn,   adopenkeyset,   adlockpessimistic    
      set   datagrid1.datasource   =   rs    
     

    网友:cuizm

    option   explicit    
      dim   conn   as   new   adodb.connection    
      dim   rs   as   new   adodb.recordset    
      dim   sql   as   string    
       
      private   sub   form_load()    
        dim   connstr   as   string    
        connstr   =   "provider=microsoft.jet.oledb.4.0;data   source=d:\mis\data.mdb"    
        conn.open   connstr    
        rs.cursorlocation   =   aduseclient    
        sql   =   "select   工号,姓名,性别,身份证号码,学历,籍贯,单位编号,职别编号,入厂日期   from   rszd"    
        rs.open   sql,   conn,   adopenkeyset,   adlockpessimistic    
        set   datagrid1.datasource   =   rs    
       
       
      private   sub   cmdfind_click()    
      if   txtname.text=""   then    
        msgbox   "请输入所要查询的名字。",16,"提示"    
        exit   sub    
      else    
        sql   =   "select   工号,姓名,性别,身份证号码,学历,籍贯,单位编号,职别编号,入厂日期   from   rszd   where   姓名="   &   txtname.text   &   ""    
      end   if    
      rs.close  
      rs.open   sql,   conn,   adopenkeyset,   adlockpessimistic    
      set   datagrid1.datasource   =   rs

    网友:lisong770818

    在每次打开记录集时,加一句   if   rs.state   then   rs.close

    网友:zhenglc

    with   rs  
          if   .state   =   adstateopen   then   .close  
          .open   sql,   conn,   ....  
      end   with  
       
      如上做查询试试用rs.filter

    .

    讨论区

    Login