ASP.net to realize the method of reading data to Data View from TXT file _ practical skills

Source: Internet
Author: User
Tags readline

This article describes the ASP.net implementation of the method of reading data from TXT file to Data view. Share to everyone for your reference, specific as follows:

#region reading data from TXT file to Data View///reading data from TXT file to Data View///</summary>///<param name= "Strexcelpath" > File path </param >///<returns> Returns a data View </returns> public static DataView Getdatafromtxt (String strtxtpath) {string Strli
  NE = "";
  DataRow Row;
   try {datatable tbl = new DataTable ();
   StreamReader sr = new StreamReader (Strtxtpath, encoding.getencoding ("GB2312")); StrLine = Sr. ReadLine (); Read first row and column properties string[] Fields = Strline.split (new char[] {'/t '})//Read each field (Tab separated) for (int k = 0; K < Fields.leng Th k++)//Add column properties to table {tbl.
   Columns.Add (Fields[k], typeof (String)); } while (StrLine = Sr. ReadLine ())!= null) {row = tbl.
    NewRow (); string[] Words = strline.split (new char[] {'/t '});//Read each field value (tab-separated) for (int j = 0; J < words. Length;
    J + +) {Row[j] = words[j]; } tbl.
   Rows.Add (row); } Sr.
   Dispose (); Sr.
   Close ();
   DataView dv = new DataView (TBL);
  return DV;
  catch {return null; }} #eNdregion

 

I hope this article will help you with ASP.net programming.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.