且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使用c#将.dat文件导入数据网格

更新时间:2022-12-08 11:39:55

你需要使用 ADO.NET [ ^ ] - OleDb [ ^ ]。



方法与此处描述的相同:访问Microsoft .NET应用程序中的Office数据 [ ^ ]。唯一的区别是你需要处理(在这种情况下) * .dat 文件作为文本文件。

要获得正确的结果,有时需要创建 schema.ini文件 [ ^ ],其中包含有关文件一般格式的信息,如:列名和数据类型信息以及其他一些数据特征。



请参阅我的过去的答案 [ ^ ]也可以找到示例代码。



试试!

hi....
I want to display .dat file into datagrid in column format ..please explain though code...

below is my .dat file format

5    ,000022,004050          ,000004,19.09.14,12341234
  4021,000100,SONU GANPAT YADA,1550  ,19.09.14,000100
  4068,000500,SANDIP BABAN AKH,9050  ,19.09.14,000500
  4119,001000,JEEVAN KAMALAKAR,41080 ,19.09.14,001000
  4139,000050,INDUBAI RAMCHAND,1400  ,19.09.14,000050
  4144,000100,SUREKHA SANJAY P,2900  ,19.09.14,000100
  4650,000100,YASHWANT GOVINDR,5300  ,19.09.14,000100
  4654,000050,SACHIN BALKRISHN,750   ,19.09.14,000050
  4656,000100,SITARAM LAXMAN G,3500  ,19.09.14,000100
  4659,000100,MAHESHKUMAR SHAR,2000  ,19.09.14,000100
  4623,001000,MEENA KISHOR KAM,43000 ,19.09.14,001000
  4626,000200,HUSSAIN . HASHAM,8000  ,19.09.14,000200
  4629,000200,SHABANA KAUSAR N,14800 ,19.09.14,000200
  4630,000100,GANESH K SUKALE ,3000  ,19.09.14,000100
  4632,000050,RAVINDRA LAXMAN ,3250  ,19.09.14,000050
  4633,000050,SAHIL HARISH YEO,3250  ,19.09.14,000050
  4634,000025,SAVITA ANIL YEOL,1700  ,19.09.14,000025
  4635,000025,ANIL LAXMAN YEWL,1700  ,19.09.14,000025
  4639,000050,NISHA SURESH NAI,2100  ,19.09.14,000050
  4640,000050,KUNAL SURESH NAI,2100  ,19.09.14,000050
  4641,000050,SANIKA SURESH NA,2100  ,19.09.14,000050
  4643,000100,SANJAY UTRESHWAR,6100  ,19.09.14,000100
  4644,000050,MANGALA LAXMAN K,3200  ,19.09.14,000050

You need to use ADO.NET[^] - OleDb[^].

The way is the same as is described here: Accessing Microsoft Office Data from .NET Applications[^]. The only difference is that that you need treat (in this case) *.dat file as a text file.
To get proper result, sometimes it needed to create schema.ini file[^], which contains information about general format of the file, like: the column name and data type information, and several other data characteristics.

See my past answers[^] too to find sample code.

Try!