如何将文本文件转换为access数据库
时 间:2008-08-28 10:56:39
作 者:UMVSOFT整理 ID:16 城市:江阴
摘 要:如何将文本文件转换为ACCESS数据库
正 文:
首先在工程中添加对Microsoft DAO 3.51 Library引用。
在窗体中添加三个命令按钮和两个MSFlexGrid.
按照下表设置和控件的属性:
控件 属性 值
--------------------------------------------------------------------
Command1 Caption "建立文本文件并显示在网格中"
Command2 Caption "传输入数据并新建一个数据库"
Command3 Caption "显示新数据库中的数据"
Grid1 Cols 5
Grid1 Rows 35
Grid2 Cols 5
Grid2 Rows 35
将下面的代码添加到窗体的声明部分
Dim nums(30) As Long
Dim names(30) As String * 20
Dim addresses(30) As String * 25
Dim ss_nums(30) As String * 12
Const DB_LONG = 4
Const DB_TEXT = 10
Const DB_LANG_GENERAL = ";LANGID=0x0809;CP=1252;COUNTRY=0"
将下面的代码添加到窗体的Load事件中
Sub Form_Load ()
Show
grid1.ColWidth(1) = 1000 'For Emp ID
grid1.ColWidth(2) = 2000 'For Emp Name
grid1.ColWidth(3) = 3000 'For Emp Addr
grid1.ColWidth(4) = 2000 'For Emp SSN
grid1.Col = 1
grid1.Row = 0
grid1.Text = "Emp ID" 'Header for Emp ID from text file
grid1.Col = 2
grid1.Row = 0
grid1.Text = "Emp Name" 'Header for Emp Name from text file
grid1.Col = 3
grid1.Row = 0
grid1.Text = "Emp Addr" 'Header for Emp Addr from text file
grid1.Col = 4
grid1.Row = 0
grid1.Text = "Emp SSN" 'Header for Emp SSN from text file
grid2.ColWidth(1) = 1000 'For Emp ID
grid2.ColWidth(2) = 2000 'For Emp Name
grid2.ColWidth(3) = 3000 'For Emp Addr
grid2.ColWidth(4) = 2000 'For Emp SSN
grid2.Col = 1
grid2.Row = 0
grid2.Text = "Employee ID" 'Header for Emp ID from DB
grid2.Col = 2
grid2.Row = 0
grid2.Text = "Employee Name" 'Header for Emp Name from DB
grid2.Col = 3
grid2.Row = 0
grid2.Text = "Employee Addr" 'Header for Emp ID from DB
grid2.Col = 4
grid2.Row = 0
grid2.Text = "Employee SSN" 'Header for Emp Name from DB
End Sub
在Command1_Click事件中加入下面的代码
Sub Command1_Click ()
For i% = 1 To 30
nums(i%) = i%
names(i%) = "John Doe # " + Str$(i%)
addresses(i%) = Str$(i%) + " Mocking Bird Lane"
If i% < 9 Then
'* Enter the following four lines as one, single line:
ss_nums(i%) = Trim$(Str$(i%) + Trim$(Str$(i%))
+ Trim$(Str$(i%)) + "-" + Trim$(Str$(i% + 1))
+ Trim$(Str$(i% + 1)) + "-" + Trim$(Str$(i%))
+ Trim$(Str$(i%)) + Trim$(Str$(i%)) + Trim$(Str$(i%)))
Else
'* Enter the following two lines as one, single line:
ss_nums(i%) = Trim$(Trim$(Str$(999)) + "-" + Trim$(Str$(88))
+ "-" + Trim$(Str$(7777)))
End If
Next i%
Open "Testdata.DAT" For Output As #1
For j% = 1 To 30
Print #1, nums(j%)
Print #1, names(j%)
Print #1, addresses(j%)
Print #1, ss_nums(j%)
Next j%
Close #1
For i% = 1 To 30 'Display results from text file
grid1.Col = 1
grid1.Row = i%
grid1.Text = nums(i%) 'Load Emp IDs
grid1.Col = 2
grid1.Row = i%
grid1.Text = names(i%) 'Load Emp Names
grid1.Col = 3
grid1.Row = i%
grid1.Text = addresses(i%) 'Load Emp Addrs
grid1.Col = 4
grid1.Row = i%
grid1.Text = ss_nums(i%) 'Load Emp SSNs
Next i%
End Sub
在Command2_Click事件中加入下面的代码
Sub Command2_Click ()
Dim newdb As Database
Dim newtb As Table
Dim newtd As New tabledef
Dim newidx As New Index
Dim fie
Access软件网官方交流QQ群 (群号:54525238)
Access源码网店
常见问答:
技术分类:
源码示例
- 【源码QQ群号19834647...(12.17)
- Access对子窗体数据进行批...(10.30)
- 最精简的组合框行来源数据快速输...(10.25)
- Access仿平台的多值选择器...(10.24)
- 【Access日期区间段查询】...(10.22)
- 【Access源码示例】VBA...(10.12)
- Access累乘示例,Acce...(10.09)
- 数值8.88,把整数8去掉,转...(10.08)
- 【Access自定义函数】一个...(09.30)
- 【Access选项卡示例】Ac...(09.09)
学习心得
最新文章
- Access快速开发平台--对上传...(11.22)
- Access快速开发平台企业版--...(11.18)
- 不会用多表联合查询,多表查询没结果...(11.16)
- 【案例分享】主键字段值含有不间断空...(11.16)
- Access快速开发平台--后台D...(11.14)
- 微软Access邀测新Monaco...(11.12)
- Access列表框左右互选、列表框...(11.11)
- 高效率在导入数据前删除记录(11.10)
- Access报价单转订单示例代码(11.08)
- Access系统自带的日期选择器不...(11.08)