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
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
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
哦,一条数据一个文本,大概如下:[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]
SQL="Select * from TB where FD_Date BETWEEN #2009-6-30# and #2007-7-31# Order by FD_Date"
from mytable
where 日期=#'2009-07-27'#
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
但我需要从第一条数据读到按条件搜索到的最后一条数据,这样循环产生txt文档。谢谢!
我的条件是"2009-07-01"到"2009-07-10"
"2009-07-01","aaa","3"
"2009-07-03","bbb","4"
"2009-07-05","ccc","5"就要从上到下依次产生3个txt文档,应该是循环读取把。
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
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
哦,一条数据一个文本,大概如下:[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]