今天工作中,遇到需要将txt文件转化到内存表dataset中,于是写了一个方法来实现:
txt文件是特定格式的,文件中,一条记录为一行,各字段之间用“|”分割(注:最后一个字段后,有”|”)各字段依次为数据库中的相应字段。
    举例如下:
    ID号|线路编码|车站编码|运行模式|模式设置日期|模式设置时间

      1|98|9821|06|20070913|211835|
      方法如下:
       

   private void button2_Click(object sender, EventArgs e)
        {
         
            string[] FieldsInArray ={ "c0", "c1", "c2", "c3", "c4", "c5", "c6", "c7" };

            DataSet ds = new DataSet();

            ds =TextFileLoader(@"D:\cpbuyaa20071018.txt","good",FieldsInArray);
            dataGridView1.DataSource = ds.Tables[0];

        }

http://www.cnblogs.com/winnxm/archive/2007/10/17/927880.html

相关文章:

  • 2021-07-30
  • 2022-12-23
  • 2022-01-02
  • 2022-01-07
  • 2022-12-23
  • 2021-06-12
  • 2022-12-23
猜你喜欢
  • 2021-06-08
  • 2022-12-23
  • 2021-11-04
  • 2022-12-23
  • 2022-12-23
  • 2021-12-03
相关资源
相似解决方案