读取DBF文件的部分代码
private void BtnOpenInitial_Click(object sender, EventArgs e)
{
OpenFileDialog file = new OpenFileDialog();
if (file.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
string path = file.FileName;
DTable dbf = new DTable();
dbf.Load(path);
if (dbf.Table.Rows.Count > 0)
{
this.GrcInitialData.DataSource = dbf.Table;
_table = new DataTable();
_table = dbf.Table;
}
}
} /// <summary>
/// 从硬盘读取dbf文件
/// </summary>
/// <param name="filepath">路径</param>
/// <returns></returns>
public int Load(String filepath)
{
FileInfo FFile = new FileInfo(filepath);
if (FFile.Exists)
{
Stream fStream = new BufferedStream(new FileStream(filepath, FileMode.Open));//main.dbf
try
{
BinaryReader bReader = new BinaryReader(fStream);
//ByteDump(fStream);
return ReadDBF(bReader);
}
catch
{
ClearDataTable();
return -1;
}
finally
{
fStream.Close();
}
}
else
{
return -1;
}
} /// <summary>
/// 读取dbf
/// </summary>
/// <param name="bReader"></param>
/// <returns></returns>
private int ReadDBF(BinaryReader bReader)
{
if (ReadHeader(bReader) == 0)
{
if (ReadFieldDesc(bReader) == 0)
{
return readRecord(bReader);
}
else
return -1;
}
else
{
return -1;
}
} /// <summary>
/// 读取记录
/// </summary>
/// <param name="bReader"></param>
/// <returns></returns>
private int readRecord(BinaryReader bReader)
{
try
{
int iRecCount = _hearder.RecordCount;
for (int i = 0; i < iRecCount; i++)
{
DRow row = new DRow();
DataRow datarow = _table.NewRow();
row.RowIndex = i; byte bRecordFlag = bReader.ReadByte(); if (bRecordFlag == 0x20)
{
row.DeleteFlag = false;
}
else if (bRecordFlag == 0x2a)
{
row.DeleteFlag = true;
}
else
{
ClearDataTable();
return -1;
} for (short j = 0; j < _columns.ColumnCount; j++)
{
DColumn col = _columns.GetColumnByIndex(j);
if (col != null)
{ DField field = new DField();
field.Column = col;
byte[] bValue = bReader.ReadBytes(col.ColumnLength);
field.FieldValue = Encoding.Default.GetString(bValue);
row.AddField(field);
UpdateRowField(datarow, field);
}
else
{
return -1;
}
}
_rows.AddRow(row);
if (!row.DeleteFlag)
_table.Rows.Add(datarow);
} //if (_hearder.RecordCount > 0)
//{
// byte endflag = bReader.ReadByte();
// if (endflag != 0x1A)
// {
// ClearDataTable();
// return -1;
// }
//}
return 0;
}
catch
{
ClearDataTable();
return -1;
}
}
读取DBF文件的部分代码的更多相关文章
- C# 解决读取dbf文件,提示Microsoft Jet 数据库引擎找不到对象的问题
前言 最新项目需要经常和dbf文件打交道,在实际场景中很多软件需要和一些老的系统进行数据交互,而这些系统都在使用foxpro数据库,读取dbf文件一般都是分为两种情况:第一:安装foxpro的驱动进行 ...
- php读取excel文件的实例代码
php读取excel文件的实例代码. 代码: <?php /** * php读取excel文件 * by www.jbxue.com */ $this->loadexcel();//半酣p ...
- python3 读取dbf文件报错 UnicodeDecodeError: 'gbk' codec can't decode
在读取dbf文件时由于编码问题报错:UnicodeDecodeError: 'gbk' codec can't decode byte 0xb5 in position 49: incomplete ...
- PHP读取超大文件的实例代码
数据量大带来的问题就是单个文件很大,能够打开这个文件相当不容易,记事本就不要指望了,果断死机 去年年底的各种网站帐号信息的数据库泄漏,很是给力啊,趁机也下载了几个数据库,准备学学数据分析家来分析一 ...
- PHPExcel读取Excel文件的实现代码
<?php require_once 'PHPExcel.php'; /**对excel里的日期进行格式转化*/ function GetData($val){ $jd = GregorianT ...
- (实用篇)PHPExcel读取Excel文件的实现代码
用PHPExcel读取Excel 2007 或者Excel2003文件,需要的朋友,可以参考下. 涉及知识点: php对excel文件进行循环读取 php对字符进行ascii编码转化,将字符转为十进 ...
- 使用Python读取Dbf文件
DBF:一种特殊的文件格式!表示数据库文件,Foxbase,Dbase,Visual FoxPro等数据库处理系统所产生的数据库文件! DBF 数据库是常用的桌面型数据库,它曾经被各企业.事业单位广泛 ...
- 读取DBF文件数据
#region 返回DBF表 public static System.Data.DataTable getDTFromDBF(string fullPath) { string pDir = Sys ...
- shp系列(六)——利用C++进行Dbf文件的写(创建)
上一篇介绍了shp文件的创建,接下来介绍dbf的创建. 推荐结合读取dbf的博客一起看! 推荐结合读取dbf的博客一起看! 推荐结合读取dbf的博客一起看! 1.Dbf头文件的创建 Dbf头文件的结构 ...
随机推荐
- hdu 5587 规律
题意:开始序列{1}; 一次变换{1,1,2}: 两次变换{1,1,2,1,2,2,3} ... 求s[n];题解:打表 S1,S2,S4,S8,S16,S32......公式 S[n]=S[最近的比 ...
- Java内存区域和判断对象“死”“活”算法
转载自: http://www.cnblogs.com/aigongsi/archive/2012/04/06/2434771.html java与C,c++有很大的不同就是java语言开发者不需要关 ...
- Linux_常用命令_04_挂载
1. mount [-t vfstype] [-o options] device dir ZC: -o 后面跟多个option的话,用逗号隔开.(例如:"mount -o rw,remou ...
- linux设备驱动编写_tasklet机制(转)
在编写设备驱动时, tasklet 机制是一种比较常见的机制,通常用于减少中断处理的时间,将本应该是在中断服务程序中完成的任务转化成软中断完成. 为了最大程度的避免中断处理时间过长而导致中断丢失,有时 ...
- jquery mobile 学习总结
<!doctype html><html lang="zh-CN"><head> <meta charset="UTF-8&qu ...
- jpeg了解
JPEG是一个压缩标准,又可分为标准 JPEG.渐进式JPEG及JPEG2000三种: ①标准JPEG:以24位颜色存储单个光栅图像,是与平台无关的格式,支持最高级 别的压缩,不过,这种压缩是有损耗的 ...
- SQL数据库基本操作语句
一.数据库及数据库表定义 1.创建基本表 create table <表名> (<列名><数据类型>[列级完整性约束条件] ...
- SqlServer_Sql防止注入
注入式攻击的详细解释SQL下面我们将以一个简单的用户登陆为例,结合代码详细解释一下SQL注入式攻击,与及他的防范措施.对于一个简单的用户登陆可能的代码如下:try{ string strUserNam ...
- commonJS — 事件处理(for Event)
for Event github: https://github.com/laixiangran/commonJS/blob/master/src/forEvent.js 代码 (function(w ...
- Canu Tutorial(canu指导手册)
链接:Canu Tutorial Canu assembles reads from PacBio RS II or Oxford Nanopore MinION instruments into u ...