vb从access中导出txt文件
各位编程大哥们好!我有一个关于VB+ACCESS的问题:请问,可否在VB中,通过什么方法将ACCESS中的某个表导出为txt文本文件?急!!望各位帮个忙啊!先谢过了!对不...
各位编程大哥们好!我有一个关于VB+ACCESS的问题:
请问,可否在VB中,通过什么方法将ACCESS中的某个表导出为txt文本文件?急!!
望各位帮个忙啊!先谢过了!
对不起,说一下,我不是说在ACCESS中如何操作,而是通过VB编程,在VB中操作数据库,导出TXT。 展开
请问,可否在VB中,通过什么方法将ACCESS中的某个表导出为txt文本文件?急!!
望各位帮个忙啊!先谢过了!
对不起,说一下,我不是说在ACCESS中如何操作,而是通过VB编程,在VB中操作数据库,导出TXT。 展开
3个回答
展开全部
ADO应该会使用吧,那就遍历一下记录集,然后用VB 的open语句来保存到文本文件中,以下为通用函数。
Private Function ExportRecordSetToFile(ByVal adoRt As Object, _
ByVal strFileName As String) As Boolean
Dim lngRecordCount As Long ' 记录数
Dim intFieldCount As Integer ' 字段数
Dim strFields As String ' 所有字段名
Dim i As Integer
Dim j As Long
Dim strTemp As String
Dim strRowContent As String
With adoRt
If .EOF And .BOF Then
ExportRecordSetToFile = False
Else
'// 取得记录总数
lngRecordCount = .RecordCount
intFieldCount = .Fields.Count - 1
For i = 0 To intFieldCount
'// 生成字段名信息
strFields = strFields & "," & .Fields(i).Name
Next
'// 去掉第一个,
strFields = Mid$(strFields, 2)
For j = 1 To lngRecordCount
strTemp = ""
For i = 0 To intFieldCount
'// 生成字段值信息
strTemp = strTemp & "," & .Fields(i).Value
Next
strRowContent = strRowContent & Mid$(strTemp, 2) & vbCrLf
.MoveNext
Next
j = FreeFile
'// 写入文件
Open strFileName For Output As #j
Print #j, strFields & vbCrLf & strRowContent
Close #j
ExportRecordSetToFile = True
End If
If .State = adStateOpen Then
.Close
End If
End With
End Function
Private Function ExportRecordSetToFile(ByVal adoRt As Object, _
ByVal strFileName As String) As Boolean
Dim lngRecordCount As Long ' 记录数
Dim intFieldCount As Integer ' 字段数
Dim strFields As String ' 所有字段名
Dim i As Integer
Dim j As Long
Dim strTemp As String
Dim strRowContent As String
With adoRt
If .EOF And .BOF Then
ExportRecordSetToFile = False
Else
'// 取得记录总数
lngRecordCount = .RecordCount
intFieldCount = .Fields.Count - 1
For i = 0 To intFieldCount
'// 生成字段名信息
strFields = strFields & "," & .Fields(i).Name
Next
'// 去掉第一个,
strFields = Mid$(strFields, 2)
For j = 1 To lngRecordCount
strTemp = ""
For i = 0 To intFieldCount
'// 生成字段值信息
strTemp = strTemp & "," & .Fields(i).Value
Next
strRowContent = strRowContent & Mid$(strTemp, 2) & vbCrLf
.MoveNext
Next
j = FreeFile
'// 写入文件
Open strFileName For Output As #j
Print #j, strFields & vbCrLf & strRowContent
Close #j
ExportRecordSetToFile = True
End If
If .State = adStateOpen Then
.Close
End If
End With
End Function
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询