从Txt文件读取数据到数据视图
2010-06-28 10:20
489 查看
#region 从Txt文件读取数据到数据视图 /// 从Txt文件读取数据到数据视图 /// </summary> /// <param name="strExcelPath">文件路径</param> /// <returns>返回一个数据视图</returns> public static DataView GetDataFromTxt(string strTxtPath) { string strLine = ""; DataRow row; try { DataTable tbl = new DataTable(); StreamReader sr = new StreamReader(strTxtPath, Encoding.GetEncoding("GB2312")); strLine = sr.ReadLine(); //读取第一行列属性 string[] Fields = strLine.Split(new char[] { '/t' });//读取每一个字段(以TAB分开) for (int k = 0; k < Fields.Length; k++) //给表增加列属性 { tbl.Columns.Add(Fields[k], typeof(string)); } while ((strLine = sr.ReadLine()) != null) { row = tbl.NewRow(); string[] words = strLine.Split(new char[] { '/t' });//读取每一个字段值(以TAB分开) 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
相关文章推荐
- asp.net实现从Txt文件读取数据到数据视图的方法
- asp.net实现从Txt文件读取数据到数据视图的方法
- asp.net实现从Txt文件读取数据到数据视图的方法
- [iOS 读取Txt] 从文件读取数据并做轮询
- 从txt文件中读取数据到二维数组
- 从数据库中读取表中数据然后写到txt文件中
- 使用Java读取xlxs文件和写入txt文件,并将数据写入到本地文件
- vc++从txt文件中读取数据
- c++从txt文件中读取数据
- 读取Excel数据和写入txt文件以及读取配置文件工具类
- Python读取txt文件数据的方法(用于接口自动化参数化数据)
- php---从txt文件读取数据
- MATLAB中批量从txt文件中读取指定行的数据保存为txt文件
- C++ 写入数据到.txt文件 从.txt文件读取数据 string字符串分割
- unity中从txt文件中读取解析json数据&&unity中json数据写入txt文件
- 一个简单的从txt文件中读取数据插入数据库
- 在j2me中读取txt文件数据
- python读取txt文件中的数据
- 在Matalb中如何读取TXT文件中的数据
- SQL 数据的导入导出,对远程(MSsql,OracleAccess,)数据库的操作以及读取Excel,txt文件中的数据