Импорт из текстового файла в gridview
I'm trying to import data from text file to grid view using the blew code : My file is like : A B C E F D C C E D D D D P Then I get the following error >Input array is longer than the number of columns in this table in c# application
Что я уже пробовал:
DataTable dt = new DataTable(); using (System.IO.TextReader tr = File.OpenText((@"d:\\My File3.log"))) { string line; while ((line = tr.ReadLine()) != null) { string[] items = line.Trim().Split(' '); if (dt.Columns.Count == 0) { // Create the data columns for the data table based on the number of items // on the first line of the file for (int i = 0; i < items.Length; i++) dt.Columns.Add(new DataColumn("Column" + i, typeof(string))); } dt.Rows.Add(items); } //show it in gridview this.GridView1.DataSource = dt; this.GridView1.DataBind();