读取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 3018 Ant Trip 欧拉回路+并查集
Ant Trip Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Problem ...
- 查询计划Hash和查询Hash
查询计划hash和查询hash 在SQL Server 2008中引入的围绕执行计划和缓冲的新功能被称为查询计划hash和查询hash.这是使用针对查询或查询计划的算法来生成二进制hash值的二进制对 ...
- iOS - OC NSFileManager 文件管理
前言 @interface NSFileManager : NSObject @interface NSFileHandle : NSObject <NSSecureCoding> NSF ...
- iOS - OC 面向对象语法
1.类 1)根类:因为类 NSObject 是层次结构的最顶层,因此称为根类. 可以将类称为子类(subclass)和父类(superclass),也可以将类称为子类和超类. 2)分类/类别(cate ...
- [转]瓦的VPS后台kiwivm面板使用+安装AMH+装VPN
参考网址:http://u-lis.com/archives/4159 ZC:网页图片保存于“百度云 OsSkill --> 全部文件 > 知识__来自网页 > 瓦 > 瓦_面 ...
- [转载] HTTP请求的TCP瓶颈分析
原文: http://bhsc881114.github.io/2015/06/23/HTTP%E8%AF%B7%E6%B1%82%E7%9A%84TCP%E7%93%B6%E9%A2%88%E5%8 ...
- Mysql ERROR 1418 (HY000): This function has none of DETERMINISTIC, NO SQL, or READS SQL DATA
ERROR 1418 (HY000): This function has none of DETERMINISTIC, NO SQL, or READS SQL DATA in its declar ...
- Java字符串处理函数
substring() 它有两种形式,第一种是:String substring(int startIndex)第二种是:String substring(int startIndex,int end ...
- Binary Tree Paths
Description: Given a binary tree, return all root-to-leaf paths. For example, given the following bi ...
- Hadoop 基本操作
1.关闭安全模式 hadoop dfsadmin -safemode leave