using System;
using System.Collections.Generic;
using System.IO;
using System.Data;
public class MyClass
{
public static void Main()
{
string path = @"D:/123321.csv";
DataTable dt = new DataTable();
StreamReader aa = new StreamReader(path);
string[] aryLine = new string[10];
bool flag = true;
while (aa.Peek() > 0)
{
string bbbb = aa.ReadLine();
aryLine = bbbb.Split(new char[] { ',' });
if (flag)
{
for (int i = 0; i < aryLine.Length; i++)
{
dt.Columns.Add(aryLine[i], typeof(string));
}
}
if (!flag)
{
DataRow dr = dt.NewRow();
for (int i = 0; i < aryLine.Length; i++)
{
dr[i] = aryLine[i];
}
dt.Rows.Add(dr);
}
flag = false;
}
Console.ReadLine();
}
}
读取CSV到DataTable
最新推荐文章于 2024-04-28 18:06:32 发布