【问题标题】:Do not want to skip the first row?不想跳过第一行?
【发布时间】:2014-04-02 14:27:20
【问题描述】:
protected void Button1_Click(object sender, EventArgs e)
{   
    string file = Server.MapPath("~/Data/") +"010414.txt";

    StreamReader reader = new StreamReader(file);
    string line = reader.ReadLine();
    DataTable dt = new DataTable();
    // DataRow row;

    while (reader.Peek() >= 0)
    {
        line = reader.ReadLine();
        string[] fields = line.Split(',');
     if (dt.Columns.Count ==0)
        {
            foreach (string field in fields)
            {
                // will add default names like "Column1", "Column2", and so on
                dt.Columns.Add();
            }
        }

        dt.Rows.Add(fields);

    }
    GridView1.DataSource = dt;
    GridView1.DataBind();
}

【问题讨论】:

  • 看起来您在创建帐户上花费的时间比解释问题的时间要多。

标签: c# asp.net datatable streamreader


【解决方案1】:

替换

StreamReader reader = new StreamReader(file);
string line = reader.ReadLine();

StreamReader reader = new StreamReader(file);
string line;

您正在阅读第一行,然后在进入循环之前将其丢弃。

【讨论】:

    猜你喜欢
    • 2014-06-07
    • 2013-08-17
    • 2013-03-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-08
    • 2013-06-13
    • 1970-01-01
    相关资源
    最近更新 更多