请问,要用VB从access数据库中读取数据,但access数据库没有记录行号。记录的数据是由3个字段组成(日期,字符串,数字)。总共有n条数据。
现在要求是把这个数据库中的每条数据导成对应的txt文本文档,就是一条数据就是一个txt文档。条件就是日期,一个日期可能对应多条数据。
请教高手,谢谢!

解决方案 »

  1.   

    select *
    from mytable
    where 日期=#'2009-07-27'#
      

  2.   


    dim cn as connection
    dim rs as recordset
    dim sql as string
    dim hfile as longset cn=new connection
    cn.open "连接数据库字符串"
    sql="select * from tb order by 日期"
    set rs=cn.execute(sql)
    hfile=freefile
    open "d:\data.txt" for output as hfile
        print #hfile,rs.getstring
    close
    set rs=nothing
    set cn=nothing
      

  3.   

    谢谢楼上的同学,
    但我需要从第一条数据读到按条件搜索到的最后一条数据,这样循环产生txt文档。谢谢!
      

  4.   

    例如:
    我的条件是"2009-07-01"到"2009-07-10"
    "2009-07-01","aaa","3"
    "2009-07-03","bbb","4"
    "2009-07-05","ccc","5"就要从上到下依次产生3个txt文档,应该是循环读取把。
      

  5.   

    2楼基础上:
    dim strPath as string 
    dim strNewPath as string
    i=1
    strpath="d:\text\"
    sql="select * from tb order by 日期"
    set rs=cn.execute(sql)
    do until rs.eof
       strnewpath=strpath & rs.filed("日期") & "_" & "第"& i  & "个文件"  
       open "d:\data.txt" for output as i
       print #hfile,rs.getstring
       close 
       i=i+1
       rs.movenext
    loop
    set rs=nothing
    set cn=nothing
      

  6.   

    2楼基础上: 
    dim strPath as string 
    dim strNewPath as string 
    i=1 
    strpath="d:\text\" 
    sql="select * from tb order by 日期" 
    set rs=cn.execute(sql) 
    do until rs.eof 
      strnewpath=strpath & rs.filed("日期") & "_" & "第"& i  & "个文件.txt"  
      open "d:\data.txt" for output as i 
      print #hfile,rs.getstring 
      close 
      i=i+1 
      rs.movenext 
    loop 
    set rs=nothing 
    set cn=nothing
      

  7.   


    哦,一条数据一个文本,大概如下:[code=VB]
    dim cn as connection
    dim rs as recordset
    dim sql as string
    dim hfile as long
    dim dt as date
    dim filename as stringset cn=new connection
    cn.open "连接数据库字符串"
    sql="select * from tb where 日期 between #2009-7-1# and #2007-7-10# order by 日期"
    set rs=cn.execute(sql)while not rs.eof
        if rs!日期<>dt then
            dt=rs!日期
            filename="d:\"& format(dt,"yyyyMMdd") & ".txt"
            hfile=freefile
            close
            open filename for output as hfile
        end if
        print #hfile,rs!日期 & vbtab & rs!字符串 & vbtab & rs!数字
      rs.movenext
    wend
    reset
    set rs=nothing
    set cn=nothing
    [/code]
      

  8.   

    SQL="Select * from TB where FD_Date BETWEEN #2009-6-30# and #2007-7-31# Order by FD_Date"