我想删除数据库中符合以下条件的记录,这是我用SQL语句写的代码,可无论如何都不行,请问专家我的代码有什么问题,如果有问题应该怎么改写?我用的是DATA控件,谢谢
data2.databasename= app.path + "\zab.mdb"
Data2.RecordSource = "DELETE  from zzgl where jfrq>=cdate('" & DTP1.Value & "') and jfrq <=cdate('" & DTP2.Value & "') "

解决方案 »

  1.   

    data2.databasename= app.path + "\zab.mdb"
    Data2.RecordSource = "DELETE  from zzgl where jfrq>='" & DTP1.Value & "' and jfrq <='" & DTP2.Value & "'"
      

  2.   

    Access里面,应该把'替换为#吧
      

  3.   

    "DELETE  from zzgl where jfrq>=#" & DTP1.Value & "# and jfrq <=#" & DTP2.Value & "#"
    你试试看,access中日期用#
    dtp是那个日期控件吧
      

  4.   

    这些方法我都试过了,不行
    这个问题的关键是data2.recordsource这个属性的使用,如果用select是选择了符合条件的记录,他赋值给了data2控件的recordsource属性,但delete是删除,已经将记录删除了,怎么能再赋值给他呢?所以
    我总觉得应该换成别的属性,但换成什么呢??请高人指点
      

  5.   

    请专家帮忙,如果SQL语句不行,还有什么方法能够将符合条件的记录一次性删除。谢谢
      

  6.   

    data2.databasename= app.path + "\zab.mdb"
    Data2.RecordSource = "DELETE  from zzgl where jfrq between cdate('" & DTP1.Value & "') and cdate('" & DTP2.Value & "') "
      

  7.   

    Data2.RecordSource = "DELETE  from zzgl where jfrq>=cdate('" & DTP1.Value & "') and jfrq <=cdate('" & DTP2.Value & "') "
    有你这样用的吗老大....
    dim cmd as ADODB.command
    cmd.execute sql
      

  8.   

    你首先定义一个 连接对象
    dim conn as new adodb.connection
    conn.open
    然后,把删除得到的记录集赋值给data的 recordsource属性
    data2.recordsource=conn.excute("DELETE  from zzgl where jfrq>=#" & DTP1.Value & "# and jfrq <=#" & DTP2.Value & "#")我 这只是大概的思路,你自己去试一下吧!:)
      

  9.   

    用DAO
    Dim dbCon as New DAO.DataBase
    Dim lsDBPath as String
    Dim lsSQL as StringlsDBPath=app.path + "\zab.mdb"
    lsSQL="DELETE  from zzgl where jfrq>=cdate('" & DTP1.Value & "') and jfrq <=cdate('" & DTP2.Value & "') "Set dbConn=OpenDatabase(lsDBPath,True)
    dbConn.Execute lsSQL