VB.NET作为一款功能比较全面的编程语言,帮助开发人员实现了许多复杂的功能需求。比如对各种类型文件的操作等等。下面我们就一起来看看关于VB.NET操作dbf文件的相关代码,来对这一知识点进行详细解读。#t#
VB.NET操作dbf文件代码示例:
- Imports System.
Data.OleDb - Imports Lion.IO.
SharpZIP.Zip - Imports Lion.IO.
SharpZIP.Checksums - Imports System.IO
- Module Module1
- Sub Main()
- 'Try
- Dim cn1 As New OleDbConnection( _
- "Provider=VFPOLEDB.1;Data
Source=C:\Temp\;")- cn1.Open()
- '-- Make some VFP data to
play with- Dim cmd1 As New OleDbCommand
( _- "Create Table TestDBF (Field1
I, Field2 C(10))", cn1)- Dim cmd2 As New OleDbCommand( _
- "Insert Into TestDBF Values
(1, '行贿)", cn1)- Dim cmd3 As New OleDbCommand( _
- "Insert Into TestDBF Values
(2, '受贿')", cn1)- cmd1.ExecuteNonQuery()
- cmd2.ExecuteNonQuery()
- cmd3.ExecuteNonQuery()
- cn1.Close()
- Dim cn2 As New OleDbConnection( _
- "Provider=VFPOLEDB.1;Data Source=C:\Temp\;")
- cn2.Open()
- Dim cmd4 As New OleDbCommand( _
- "Select * From TestDBF", cn2)
- Dim da1 As New OleDbDataAdapter(cmd4)
- Dim ds1 As New DataSet
- Dim dr1 As DataRow
- da1.Fill(ds1)
- For Each dr1 In ds1.Tables(0).Rows
- Console.WriteLine(dr1.Item(1).ToString())
- Next
- cn2.Close()
- Dim crc As New Crc32
- Dim s As New ZipOutputStream(System.
IO.File.Create("c:\temp\dbf.zip"))- s.SetLevel(6)
- Dim fs As FileFileStream = File.Open
Read("c:\temp\testdbf.dbf")- Dim b(fs.Length - 1) As Byte'c#中的
语句为byte[] b = byte[fs.Length ];要注意这点- fs.Read(b, 0, b.Length)
- Dim entry As ZipEntry = New ZipEntry
("c:\temp\testdbf.dbf")- entry.DateTime = DateTime.Now
- entry.Size = fs.Length
- fs.Close()
- crc.Reset()
- crc.Update(b)
- entry.Crc = crc.Value
- s.PutNextEntry(entry)
- s.Write(b, 0, b.Length)
- s.Finish()
- s.Close()
- Console.ReadLine()
- 'Catch e As Exception
- 'MsgBox(e.ToString())
- 'End Try
- End Sub
- End Module
VB.NET操作dbf文件相关操作技巧就为大家介绍到这里。