小弟想请教各位高人!我想清除数据库中的空白数据!我的程序如下:
If Data1.Recordset.RecordCount <> 0 Then
        Data1.Recordset.MoveFirst
        For l = 1 To Data1.Recordset.RecordCount
            If Text1.Text = "" Then  'text1.text 为与库相联系的一个文本框
            Data1.Recordset.Delete
            Data1.Refresh
            Data1.Recordset.MoveNext
            If Data1.Recordset.EOF Then
              Data1.Recordset.MoveFirst
               If Data1.Recordset.BOF Then
                 End If
            End If
            Else
            Data1.Recordset.MoveNext
            If Data1.Recordset.EOF Then
              Data1.Recordset.MoveFirst
               If Data1.Recordset.BOF Then
                 End If
            End If
            
            End If
但不知为何!当有连续几个(2个以上)的空纪录!总有几个空纪录不能删除!不知如何改写!请高人指点一二!小弟不胜感激!

解决方案 »

  1.   

    next 哪里去了?
    最外面的end if呢?
    If Text1.Text = "" Then  用这个判断好吗?
    还是这样吧: if Data1.Recordset.fields(l-1) & "" = "" then还有,你要是一边循环一边删除数据的话,不如从记录集的尾部开始
    For l = Data1.Recordset.RecordCount to 1
    判断并操作:Data1.Recordset.fields(l-1)
      

  2.   

    Next
            Else
            End If
     不好意思!这回补全了!接到上面就可以了!我试了,还是不行  !还当如何改进?拜托了!
      

  3.   

    你的代码很多错误,建议不要用。
    在原基础上修改:
    If Data1.Recordset.RecordCount<=0 Then
      exit sub
    end if
    data1.movefirst
    do while not data1.recordset.eof
      if iif(isnull(data1.recordset.fields("").values),"",data1.recordset.fields("").values)="" then
      data1.recordset.delete
      end if
      data1.recordset.movenext
    loop
    最好自定义
    dim conn as new adodb.connection
    conn.open connectionstring
    conn.execute "delete from table where field is null or field=''"
      

  4.   

    连接数据库最好不要用data控件
    试试ADO,DAO和DBEngine对象