请帮助我看一下这处程序:如何将Access(*.mdb)文件转换为其它的文件格式?

jzp12 2007-06-04 10:04:40
我想实现将其转换为如格式的文件.
*.DBF
*.MDB
*.XLS
*.DB
现在已经现实转换为*.XLS格式的文件,
但是其它的都不能,实现程序代码如下:帮我看看到底那里错了?

Public Class Form1
Inherits System.Windows.Forms.Form
Dim conn As New ADODB.Connection
Dim rsExport As New ADODB.Recordset

#Region " Windows 窗体设计器生成的代码 "

Public Sub New()
MyBase.New()

'该调用是 Windows 窗体设计器所必需的。
InitializeComponent()

'在 InitializeComponent() 调用之后添加任何初始化

End Sub

'窗体重写 dispose 以清理组件列表。
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

'Windows 窗体设计器所必需的
Private components As System.ComponentModel.IContainer

'注意: 以下过程是 Windows 窗体设计器所必需的
'可以使用 Windows 窗体设计器修改此过程。
'不要使用代码编辑器修改它。
Friend WithEvents RadioButton1 As System.Windows.Forms.RadioButton
Friend WithEvents RadioButton2 As System.Windows.Forms.RadioButton
Friend WithEvents RadioButton4 As System.Windows.Forms.RadioButton
Friend WithEvents Button1 As System.Windows.Forms.Button
Friend WithEvents Dialog1 As System.Windows.Forms.SaveFileDialog
Friend WithEvents DataGrid1 As System.Windows.Forms.DataGrid
Protected Friend WithEvents RadioButton3 As System.Windows.Forms.RadioButton
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.RadioButton1 = New System.Windows.Forms.RadioButton
Me.RadioButton2 = New System.Windows.Forms.RadioButton
Me.RadioButton3 = New System.Windows.Forms.RadioButton
Me.RadioButton4 = New System.Windows.Forms.RadioButton
Me.Button1 = New System.Windows.Forms.Button
Me.Dialog1 = New System.Windows.Forms.SaveFileDialog
Me.DataGrid1 = New System.Windows.Forms.DataGrid
CType(Me.DataGrid1, System.ComponentModel.ISupportInitialize).BeginInit()
Me.SuspendLayout()
'
'RadioButton1
'
Me.RadioButton1.Location = New System.Drawing.Point(24, 32)
Me.RadioButton1.Name = "RadioButton1"
Me.RadioButton1.Size = New System.Drawing.Size(120, 24)
Me.RadioButton1.TabIndex = 0
Me.RadioButton1.Text = "Foxpro格式"
'
'RadioButton2
'
Me.RadioButton2.Location = New System.Drawing.Point(24, 96)
Me.RadioButton2.Name = "RadioButton2"
Me.RadioButton2.TabIndex = 1
Me.RadioButton2.Text = "Access格式"
'
'RadioButton3
'
Me.RadioButton3.Location = New System.Drawing.Point(216, 32)
Me.RadioButton3.Name = "RadioButton3"
Me.RadioButton3.Size = New System.Drawing.Size(128, 24)
Me.RadioButton3.TabIndex = 2
Me.RadioButton3.Text = "Excel格式"
'
'RadioButton4
'
Me.RadioButton4.Location = New System.Drawing.Point(216, 96)
Me.RadioButton4.Name = "RadioButton4"
Me.RadioButton4.Size = New System.Drawing.Size(120, 24)
Me.RadioButton4.TabIndex = 3
Me.RadioButton4.Text = "Paradox4.x格式"
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(104, 160)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(136, 40)
Me.Button1.TabIndex = 4
Me.Button1.Text = "转换"
'
'DataGrid1
'
Me.DataGrid1.DataMember = ""
Me.DataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText
Me.DataGrid1.Location = New System.Drawing.Point(256, 128)
Me.DataGrid1.Name = "DataGrid1"
Me.DataGrid1.TabIndex = 5
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
Me.ClientSize = New System.Drawing.Size(432, 270)
Me.Controls.Add(Me.DataGrid1)
Me.Controls.Add(Me.Button1)
Me.Controls.Add(Me.RadioButton4)
Me.Controls.Add(Me.RadioButton3)
Me.Controls.Add(Me.RadioButton2)
Me.Controls.Add(Me.RadioButton1)
Me.Name = "Form1"
Me.Text = "Form1"
CType(Me.DataGrid1, System.ComponentModel.ISupportInitialize).EndInit()
Me.ResumeLayout(False)

End Sub

#End Region

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'连接数据可并打开记录集
conn.CursorLocation = ADODB.CursorLocationEnum.adUseServer
conn.Open("PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=" & Application.StartupPath & "\jzp.mdb;")
rsExport.Open("Select * from Customers", conn, ADODB.CursorTypeEnum.adOpenStatic, ADODB.LockTypeEnum.adLockOptimistic) '初始化对话框

With Dialog1
.Filter = "FoxBase/FoxPro(*.DBF)|*.DBF|Access8.0(*.MDB)|*.MDB|Excel8.0(*.XLS)|*.XLS|Paradox4.x(*.DB)|*.DB"
.Title = "导出文件为"
End With
End Sub
...全文
235 1 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
jzp12 2007-06-04
  • 打赏
  • 举报
回复
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim myPath As Object
Dim myStr As String
Dim myPos As Short
Dim mdbTable As String
Dim Export_Str As Object
Try
'**************处理选择的各种表的导出
With Dialog1
If RadioButton1.Checked Then
.FilterIndex = 1
.ShowDialog()
myStr = StrReverse(.FileName) '串取反
myPos = InStr(myStr, "\") '在反字符串中,找从左开始第一个位置
myPath = StrReverse(Mid(myStr, myPos)) '取目录部分,并还原。
myStr = StrReverse(Strings.Left(myStr, myPos - 1)) '取文件名
Export_Str = "select * into [dBaseⅢ;database= " & myPath & "]." & myStr & "from Customers"
.DefaultExt = "*.DBF"
ElseIf RadioButton2.Checked Then
mdbTable = InputBox("请给导出到MDB文件的表确定表名")
.FilterIndex = 2
.ShowDialog()
Export_Str = "select * into [;database= " & .FileName & "]." & mdbTable & "from Customers"
.DefaultExt = "*.MDB"
ElseIf RadioButton3.Checked Then
.FilterIndex = 3
.ShowDialog()
Export_Str = "select * into [Excel 8.0;database=" & .FileName & "].Customers from Customers"
.DefaultExt = "*.XLS"
ElseIf RadioButton4.Checked Then
.FilterIndex = 4
.ShowDialog()
myStr = StrReverse(.FileName) '串取反
myPos = InStr(myStr, "\") '在反字符串中,找从左开始第一个\的位置
myPath = StrReverse(Strings.Left(myStr, myPos - 1)) '取文件名
Export_Str = "select * into [Paradox4.X;database=" & myPath & "]." & myStr & " from Customers"
.DefaultExt = "*.DB"
End If
End With

'************生成文件
System.Diagnostics.Debug.WriteLine(Export_Str)
If rsExport.State = 1 Then
rsExport.Close()
End If
If Dir(Dialog1.FileName) <> "" Then
'防用户没选文件
If Dialog1.FilterIndex <> 2 Then
Kill((Dialog1.FileName))
End If
rsExport.Open(Export_Str, conn, ADODB.CursorTypeEnum.adOpenStatic, ADODB.LockTypeEnum.adLockOptimistic)
Else
rsExport.Open(Export_Str, conn, ADODB.CursorTypeEnum.adOpenStatic, ADODB.LockTypeEnum.adLockOptimistic)

End If
Catch
Exit Sub
End Try
End Sub

Private Sub DataGrid1_Navigate(ByVal sender As System.Object, ByVal ne As System.Windows.Forms.NavigateEventArgs) Handles DataGrid1.Navigate

End Sub

Private Sub RadioButton3_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton3.CheckedChanged

End Sub

Private Sub RadioButton1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton1.CheckedChanged

End Sub

Private Sub RadioButton2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton2.CheckedChanged

End Sub

Private Sub RadioButton4_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton4.CheckedChanged

End Sub
End Class

16,722

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧