vb6如何将ACCESS数据表里全部数据以TXTl格式保存到本地计算机
条件数据库名为DB.mdb,表名为CNSJ;有A,B,C,D,E五个字段,要求A,B,C,D,E字段按一定的字节数固定排版,能具体点,谢谢!Private Sub Form_Load()
Dim cNn As ADODB.Connection
Dim cOn As ADODB.Recordset
Dim cWn As String
Dim sTa As String
Set cNn = New ADODB.Connection
Set cOn = New ADODB.Recordset
'连接数据
cWn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= " & App.Path & "\db.mdb;Mode=ReadWrite;Persist_ Security Info=False;Jet OLEDB:Database Password=1234 "
Dim aDstateclose As ApplicationStartConstants
cNn.Open cWn
Select Case cNn.State
Case adstateclose
sTa = "adStateclosed"
Case adStateOpen
sTa = "adStateOpen"
End Select
'显示连接状态
MsgBox "连接成功", , sTa
cOn.Open "select * from chsj ", cNn
cOn.Close
End Sub
数据库已连接通
下面不会写了,高手,我是一个初学者,对VB编程不懂,能帮写下吗.因为是新手,没有多少分,望见谅
--------------------编程问答-------------------- 这个, 如果在有安装access的电脑上用Access对象的导出命令来做的话,效率比用数据库方法要高几十上百倍.
dim Acc as new access.application
...
ACC.OpenCurrentDatabase DBFileName ' DBFileName 就是mdb文件全路径和文件名
....
ACC.DoCmd.OutputTo acOutputTable, "Sheet3", acFormatXLS, XlsFileName
'将acOutputTable表导出到XlsFileName的Sheet3, 如果是要导出为文本格式,则更改acFormatXLS参数即可
具体参数楼主请自行百度或google --------------------编程问答-------------------- Dim strTmp As String
......
cOn.Open "select * from chsj ", cNn
strTmp = cOn.GetString()
cOn.Close
Set cOn = Nothing
cNn.Close
Set cNn = Nothing
Open App.Path & "\CNSJ.txt" For Output As #1
Print #1, strTmp
Close #1 --------------------编程问答-------------------- [我本是个诗人,直到膝盖中了一箭]谢谢您!回帖是个解决问题方法,但我对access操作不懂,以后再学. --------------------编程问答-------------------- [多想想]您好!回帖已试,导出文档排版无序,我的数据里5个字段每个字段的字节数不统一有的含空格,但要导出的5个字段分别为8,17,13,13,21字节,请指教. --------------------编程问答-------------------- 这是数据表里的数据:
JZR ZH JF DF DJH
20110901 12345678901234 10,000.00 0.00 1040323100478764
20110901 12345678901234 0.00 250,000.00 20110901
20110901 12345678901234 4,500.00 0.00 1040323100559608
20110901 12345678901234 5,000.00 0.00 1040323100478884
20110901 12345678901234 5,534.00 0.00 1040323100559609
以上某些字段内有空格
需要导出文本格式如下所示:
JZR ZH JF DF DJH
20110901 12345678901234 10000.00 0.00 00478764
20110901 12345678901234 0.00 250000.00 20110901
20110901 12345678901234 4500.00 0.00 00559608
20110901 12345678901234 5000.00 0.00 00478884
20110901 12345678901234 5534.00 0.00 00559609
补充:VB , 数据库(包含打印,安装,报表)