用update更改记录,cnn执行 execute:SqlStr="select * from "&TabName 
set rst=ExecuteSql(SqlStr,MsgText)  '返回记录集 
...... 
...... 
 rst.move  intCount  '----- >定位记录集指针 
 for i = FfmNo To ColNum - 1 
    SqlStr = "update " & TabName & " set " & frmDataShow.rst.Fields(i).Name & "='" & TxtModify(i).Text & "' where " & frmDataShow.rst.Fields(i).Name &"='" & frmDataShow.dbfList.TextMatrix(intCount, i + 1) & "'" 
    Set rst = ExecuteSQL(SqlStr, MsgText) 
 Next i 
 frmDataShow.dbfList.Refresh 
改成上面这样后,虽然没有错误了,但是记录集没有被更改。 
其中的ExecuteSQL函数是在标准模块中这样定义的: 
...... 
      cnn.ConnectionString = "Provider=MSDASQL.1;Persist Security
Info=False ;Data Sources=dBASE Files;Initial Catalog=" & PathStr 
      cnn.Open "Driver={Microsoft dBASE Driver (*.dbf)};" & _ 
             "DriverID=277;" & "Dbq=" & PathStr 
      If InStr("INSERT,DELETE,UPDATE", UCase$(sTokens(0))) Then    '对已存在的表的编辑操作 
        Debug.Print "test1" 
        Debug.Print SQL 
        cnn.Execute SQL 
        Debug.Print "test2" 
        Msgstring = sTokens(0) & " query successful" 
        cnn.Close                         
      Else                                '对表的打开 
        rst.CursorLocation = adUseClient 
        rst.Open SQL, cnn, adOpenDynamic, adLockOptimistic 
        'rst.MoveLast     'get RecordCount 
        Set ExecuteSQL = rst 
      End If 
...... 
debug.print显示的信息: test1 
update sample set STATE_PROV='test' where STATE_PROV='' 
test1 
update sample set ZIP_PST_CD='' where ZIP_PST_CD='' 
test1 
update sample set COUNTRY='Cyprus' where COUNTRY='Cyprus' 
test1 
update sample set PHONE='357-6-876708' where PHONE='357-6-876708' 
test1 
update sample set FRST_CNTCT='1990-04-12' where FRST_CNTCT='1990-04-12' 
ormat.' where DESCRIPT='3rd side is in CAV format.' 
test1 
update sample set STUDIO='MGM/UA' where STUDIO='MGM/UA' 
test1 
update sample set KIDS='True' where KIDS='True' 
从debug看好象是没有执行cnn.execute SQL。也没有错误提示消息。是什么道理呢? 

解决方案 »

  1.   

    建议你使用Command对象,示例如下:dim objAdoCmd as new ADODB.commandIf InStr("INSERT,DELETE,UPDATE", UCase$(sTokens(0))) Then    '对已存在的表的编辑操作 
    'begin
    with objAdoCmd  
        .ActiveConnection = cnn
        .CommandType = adCmdText
        .CommandText = SQL
        .Execute
    end with
    'end
    Debug.Print SQL 
            cnn.Execute SQL 
            Debug.Print "test2" 
            Msgstring = sTokens(0) & " query successful" 
            cnn.Close                         
          Else                                '对表的打开 
            rst.CursorLocation = adUseClient 
            rst.Open SQL, cnn, adOpenDynamic, adLockOptimistic 
            'rst.MoveLast     'get RecordCount 
            Set ExecuteSQL = rst 
          End If 
      

  2.   

    试了,还是不行!(表是dbf格式的)