Hallo,

i have a Csv file,i would like to read ,convert it and than represent it with Datagrid

the fonction who read my csv

public List<String[]> Parse_CSV(String File_Path)
        {
            List<string[]> Parse_Data = new List<string[]>();
            try
            {
                using (StreamReader Read_File = new StreamReader(File_Path))
                {
                    string Line;
                    string[] Row;

                    while ((Line = Read_File.ReadLine()) != null)
                    {
                        Row = Line.Split(',');
                        Parse_Data.Add(Row);

                        MessageBox.Show(Parse_Data.ToString());
                        MessageBox.Show(Row.ToString());
                                            }
                }

            }
            catch (Exception e) 
            {

                MessageBox.Show( e.Message);
            
            }

            return Parse_Data;
    
    
    
    
        }

i join a example of my Csv file

thx in advance

Attachments
Date	Kollektor (C)	Brauchwasserbereich (C)	Speicher unten (C)	Senke (C)	Quelle (C)	Vorlauftemp.      WMZ (C)	Rcklauftemp.     WMZ (C)	Durchfluss WMZ (l/min)	Momentleistung WMZ (kW)	Tageslaufzeit solar (h)	Gesamtlaufzeit solar (h)	Tagesenergie (kWh)	Gesamtenergie (MWh)
2011-03-26 06:00:01				48.1	52.4	0	0	0	0	0	180	0	0
2011-03-26 06:05:01	7.8	45.2	29.8	48.1	52.3	0	0						
2011-03-26 06:10:01	8.2	45.1	30.2	48.1	52.3	0	0						
2011-03-26 06:15:01	8.7	45.1	30.6	48.1	52.3	0	0						
2011-03-26 06:20:01	9	45.1	31.2	48.1	52.3	0	0						
2011-03-26 06:25:01	9.5	45.1	33.8	48	52.3	0	0						
2011-03-26 06:30:01	9.9	46.1	42.8	48	52.3	0	0						
2011-03-26 06:35:01	10.5	45.6	43.2	47.1	52.3	0	0						
2011-03-26 06:40:01	11.1	45.3	42.6	46.3	52.3	0	0						
2011-03-26 06:45:02	11.8	45.3	41.4	46.1	52.3	0	0						
2011-03-26 06:50:02	12.6	45.3	40.3	46	52.3	0	0						
2011-03-26 06:55:01	13.8	45.3	38.7	45.9	52.3	0	0						
2011-03-26 07:00:01	15.1	45.3	37	45.8	52.3	0	0	0	0	0	180	0	0
2011-03-26 07:05:01	16.5	45.3	35.6	45.8	52.3	0	0						
2011-03-26 07:10:01	17.7	45.3	34.4	45.8	52.2	0	0						
2011-03-26 07:15:01	18.4	45.3	33.7	45.7	52.1	0	0						
2011-03-26 07:20:01	18.8	45.1	33	45.6	52.1	0	0						
2011-03-26 07:25:02	19.5	45.1	32.4	45.6	52.1	0	0						
2011-03-26 07:30:01	20.3	45.1	32	45.5	52.1	0	0						
2011-03-26 07:35:01	21.3	45.1	31.7	45.5	52.1	0	0						
2011-03-26 07:40:01	22.8	45	31.5	45.5	52.1	0	0						
2011-03-26 07:45:01	24.5	45	31.3	45.3	52.1	0	0						
2011-03-26 07:50:01	26.3	44.9	31.3	45.3	52.1	0	0						
2011-03-26 07:55:01	28.2	44.8	31.1	45.3	52.1	0	0						
2011-03-26 08:00:01	30.1	44.8	31.2	45.3	52.1	0	0	0	0	0	180	0	0
2011-03-26 08:05:01	31.6	44.8	31	45.1	52.1	0	0						
2011-03-26 08:10:01	33.2	44.6	31	45.1	52.1	0	0						
2011-03-26 08:15:02	34.8	44.6	30.8	45.1	52	0	0						
2011-03-26 08:20:01	35.6	44.6	30.8	45	52	0	0						
2011-03-26 08:25:01	36.8	44.5	30.8	45	52	0	0						
2011-03-26 08:30:01	37.8	44.5	30.8	44.9	52	0	0						
2011-03-26 08:35:01	38.4	44.5	30.8	44.8	52	0	0						
2011-03-26 08:40:01	38.5	44.4	30.8	44.8	52	0	0						
2011-03-26 08:45:01	37.3	44.3	30.8	44.8	52	0	0						
2011-03-26 08:50:01	36.6	44.3	30.8	44.8	52	0	0						
2011-03-26 08:55:01	36	44.3	30.8	44.8	51.9	0	0						
2011-03-26 09:00:01	35.1	44.3	30.8	44.8	51.9	0	0	0	0	0	180	0	0
2011-03-26 09:05:01	34.1	44.2	30.8	44.8	51.9	0	0						
2011-03-26 09:10:01	33.8	44.1	30.8	44.8	51.8	0	0						
2011-03-26 09:15:01	34.5	44.1	30.8	44.8	51.8	0	0						
2011-03-26 09:20:01	35.5	44.1	30.8	44.8	51.8	0	0						
2011-03-26 09:25:01	38.2	44	30.8	44.8	51.8	0	0						
2011-03-26 09:30:01	34.9	44	30.7	44.8	51.8	0	0						
2011-03-26 09:35:01	35.5	43.9	30.8	44.8	51.8	0	0						
2011-03-26 09:40:01	36.8	43.9	30.9	44.8	51.8	0	0						
2011-03-26 09:45:01	36.2	43.8	31	44.8	51.8	0	0						
2011-03-26 09:50:01	38.7	43.8	31.1	44.8	51.8	0	0						
2011-03-26 09:55:01	39.6	43.8	31.5	44.8	51.8	0	0						
2011-03-26 10:00:01	40.2	43.8	31.7	44.8	51.8	0	0	0	0	1	181	0	0
2011-03-26 10:05:01	40.5	43.6	32.1	44.8	51.8	0	0						
2011-03-26 10:10:01	40	43.6	32.5	44.8	51.6	0	0						
2011-03-26 10:15:01	38.7	43.6	32.8	44.8	51.6	0	0						
2011-03-26 10:20:01	40.6	43.5	33.1	44.8	51.6	0	0						
2011-03-26 10:25:01	41.3	43.5	33.3	44.8	51.6	0	0						
2011-03-26 10:30:01	40.5	43.6	33.6	44.6	51.6	0	0						
2011-03-26 10:35:01	42.1	43	33.9	44.1	51.6	0	0						
2011-03-26 10:40:01	40.1	42.6	34.3	43.9	51.6	0	0						
2011-03-26 10:45:01	40.5	42.7	34.5	44.2	51.6	0	0						
2011-03-26 10:50:02	39.3	42.6	34.6	44.6	51.5	0	0						
2011-03-26 10:55:01	40.5	42.7	34.8	44.7	51.4	0	0						
2011-03-26 11:00:01	39.5	42.6	35	44.4	51.2	0	0	0	0	2	182	0	0
2011-03-26 11:05:01	41.1	42.6	35.1	44.5	51.1	0	0						
2011-03-26 11:10:01	42	42.6	35.2	44.3	51	0	0						
2011-03-26 11:15:02	44.7	42.7	35.5	44.2	50.9	0	0						
2011-03-26 11:20:01	43	42.5	35.5	44	50.8	0	0						
2011-03-26 11:25:01	44.6	42.5	35.5	43.9	50.6	0	0						
2011-03-26 11:30:01	44.8	42.5	35.5	43.8	50.4	0	0						
2011-03-26 11:35:01	41.3	42.5	35.5	43.7	50.3	0	0						
2011-03-26 11:40:01	35.3	42.5	35.5	43.6	50.1	0	0						
2011-03-26 11:45:01	35.6	42.5	35.5	43.5	50	0	0						
2011-03-26 11:50:01	36.1	42.5	35.5	43.5	49.8	0	0						
2011-03-26 11:55:01	36.3	42.3	35.3	43.4	49.7	0	0						
2011-03-26 12:00:01	36.3	42.3	35.3	43.3	49.5	0	0	0	0	2	182	0	0
2011-03-26 12:05:01	36.8	42.3	35.2	43.3	49.4	0	0						
2011-03-26 12:10:01	39.5	42.3	35	43.1	49.3	0	0						
2011-03-26 12:15:01	42.3	42.3	34.8	43.1	49.2	0	0						
2011-03-26 12:20:01	46.9	42.2	34.7	43	49	0	0						
2011-03-26 12:25:01	47	42.2	34.6	42.9	48.8	0	0						
2011-03-26 12:30:01	49.3	42.3	34.4	42.8	48.7	0	0						
2011-03-26 12:35:01	47.9	42.3	34.2	42.8	48.6	0	0						
2011-03-26 12:40:01	38	41.9	34	43	48.4	0	0						
2011-03-26 12:45:01	41	41.8	33.8	43	48.3	0	0						
2011-03-26 12:50:01	40.8	41.8	33.6	43	48.2	0	0						
2011-03-26 12:55:02	37.7	41.8	33.6	43	48.1	0	0						
2011-03-26 13:00:01	54	41.8	33.5	43	48	0	0	0	0	2	182	0	0
2011-03-26 13:05:01	45.8	41.8	33.3	43.1	47.8	0	0						
2011-03-26 13:10:01	45.9	41.7	33.1	43.1	47.7	0	0						
2011-03-26 13:15:02	47.3	41.7	32.8	43	47.6	0	0						
2011-03-26 13:20:01	44.8	41.7	32.5	43.3	47.5	0	0						
2011-03-26 13:25:01	45.4	41.9	32.7	43.2	47.3	0	0						
2011-03-26 13:30:01	47.1	41.9	32.5	43.1	47.2	0	0						
2011-03-26 13:35:02	46.7	42	32.3	43.1	47.1	0	0						
2011-03-26 13:40:01	47.5	42.2	32.2	43.3	47	0	0						
2011-03-26 13:45:01	48.6	42.1	31.9	43.3	46.8	0	0						
2011-03-26 13:50:01	49	42.5	31.8	43.5	46.8	0	0						
2011-03-26 13:55:01	47.7	42.8	31.7	43.5	46.6	0	0						
2011-03-26 14:00:01	48	43	31.5	43.5	46.5	0	0	0	0	2	182	0	0
2011-03-26 14:05:01	46.1	43.2	31.3	43.6	46.4	0	0						
2011-03-26 14:10:01	42.7	43.2	31.7	43.5	46.2	0	0						
2011-03-26 14:15:01	42.8	43	31.7	43.3	46.2	0	0						
2011-03-26 14:20:01	43.1	43	31.5	43.3	46	0	0						
2011-03-26 14:25:01	46.4	42.8	31.4	43.1	46	0	0						
2011-03-26 14:30:01	39.8	42.8	31.2	43.1	45.9	0	0						
2011-03-26 14:35:01	39	42.8	31.6	43.1	45.8	0	0						
2011-03-26 14:40:01	39.1	42.8	31.7	43	45.7	0	0						
2011-03-26 14:45:01	40.2	42.7	31.6	43	45.7	0	0						
2011-03-26 14:50:01	44.8	42.6	31.5	42.8	45.5	0	0						
2011-03-26 14:55:01	43.9	42.4	31.3	42.8	45.4	0	0						
2011-03-26 15:00:01	45.8	42.5	31.7	43	45.5	0	0	0	0	3	183	0	0
2011-03-26 15:05:01	46.4	42.5	31.7	43	45.3	0	0						
2011-03-26 15:10:01	46.5	42.5	31.5	42.8	45.3	0	0						
2011-03-26 15:15:01	47.8	42.3	31.5	42.7	45.2	0	0						
2011-03-26 15:20:01	44.1	42.3	31.4	42.7	45.2	0	0						
2011-03-26 15:25:01	45.7	42.3	31.7	42.7	45.1	0	0						
2011-03-26 15:30:01	46.4	42.3	31.7	42.7	45	0	0						
2011-03-26 15:35:01	46.6	42.3	31.6	42.5	45	0	0						
2011-03-26 15:40:01	46.1	42.2	31.5	42.5	45	0	0						
2011-03-26 15:45:01	36.1	42.1	31.5	42.3	44.8	0	0						
2011-03-26 15:50:01	34.7	42	31.9	42.3	44.8	0	0						
2011-03-26 15:55:01	33.8	41.9	31.9	42.1	44.7	0	0						
2011-03-26 16:00:01	32.8	41.8	31.8	42.1	44.6	0	0	0	0	3	183	0	0
2011-03-26 16:05:01	31.8	41.8	31.8	42	44.6	0	0						
2011-03-26 16:10:01	30.8	41.6	31.7	42	44.5	0	0						
2011-03-26 16:15:01	29.8	41.6	31.7	41.8	44.5	0	0						
2011-03-26 16:20:01	28.7	41.5	31.5	41.8	44.5	0	0						
2011-03-26 16:25:01	27.5	41.5	31.4	41.6	44.3	0	0						
2011-03-26 16:30:01	26.3	41.5	31.3	41.6	44.3	0	0						
2011-03-26 16:35:01	24.8	41.3	31.2	41.6	44.3	0	0						
2011-03-26 16:40:01	23.8	41.3	31.1	41.5	44.1	0	0						
2011-03-26 16:45:01	22.8	41.2	31	41.5	44.2	0	0						
2011-03-26 16:50:01	21.6	41.1	30.8	41.3	44.1	0	0						
2011-03-26 16:55:01	20.6	41	30.8	41.3	44	0	0						
2011-03-26 17:00:01	19.6	41	30.7	41.3	43.9	0	0	0	0	3	183	0	0
2011-03-26 17:05:01	19	40.9	30.7	41.2	43.6	0	0						
2011-03-26 17:10:01	18.2	40.9	31.3	41.5	44.6	0	0						
2011-03-26 17:15:01	17.5	40.8	37	41.8	46.1	0	0						
2011-03-26 17:20:01	16.8	40.8	39	42.3	46.8	0	0						
2011-03-26 17:25:01	16.1	40.8	40.2	43	47.5	0	0						
2011-03-26 17:30:01	15.7	40.8	41.2	42.8	48.1	0	0						
2011-03-26 17:35:01	15.1	40.5	42.5	41.8	49.5	0	0						
2011-03-26 17:40:01	14.8	40.3	43.8	41.6	51.4	0	0						
2011-03-26 17:45:01	14.5	40.3	44.8	43.3	53.3	0	0						
2011-03-26 17:50:01	14.3	40.3	45.5	44.9	54.8	0	0						
2011-03-26 17:55:01	14	40.3	46.3	46.1	55.8	0	0						
2011-03-26 18:00:01	13.9	40.3	47.4	47.4	57.3	0	0	0	0	3	183	0	0
2011-03-26 18:05:01	13.7	40.3	47.5	47.5	57.7	0	0						
2011-03-26 18:10:01	13.5	40.3	47.5	47.6	57.7	0	0						
2011-03-26 18:15:01	13.4	40.3	47.3	47.6	57.6	0	0						
2011-03-26 18:20:01	13.2	40.4	47.2	47.7	57.5	0	0						
2011-03-26 18:25:01	13	40.3	47.1	47.7	57.4	0	0						
2011-03-26 18:30:01	13	40.3	47	47.6	57.3	0	0						
2011-03-26 18:35:01	12.9	40.3	46.8	47.7	57.1	0	0						
2011-03-26 18:40:01	12.8	40.4	46.7	47.7	57.1	0	0						
2011-03-26 18:45:01	12.7	40.3	46.5	47.6	56.8	0	0						
2011-03-26 18:50:01	12.5	40.3	46.3	47.6	56.6	0	0						
2011-03-26 18:55:01	12.6	40.3	46.3	47.5	56.6	0	0						
2011-03-26 19:00:01	12.6	40.2	46.2	47.5	56.4	0	0	0	0	3	183	0	0
2011-03-26 19:05:01	12.3	40.2	46	47.5	56.3	0	0						
2011-03-26 19:10:01	12.4	40.3	45.9	47.4	56.2	0	0						
2011-03-26 19:15:01	12.2	40.2	45.8	47.3	56	0	0						
2011-03-26 19:20:01	12.2	40.2	45.7	47.3	55.8	0	0						
2011-03-26 19:25:01	12	40.2	45.5	47.3	55.8	0	0						
2011-03-26 19:30:01	11.9	40.2	45.3	47.3	55.6	0	0						
2011-03-26 19:35:01	11.8	40.2	45.2	47.2	55.5	0	0						
2011-03-26 19:40:01	11.7	40.2	45	47.2	55.3	0	0						
2011-03-26 19:45:01	11.6	40.2	44.8	47.2	55.2	0	0						
2011-03-26 19:50:01	11.5	40.2	44.6	47.1	55.1	0	0						
2011-03-26 19:55:02	11.5	40.2	44.4	47.1	55	0	0						
2011-03-26 20:00:01	11.4	40.2	43.9	47	54.9	0	0	0	0	3	183	0	0
2011-03-26 20:05:01	11.5	40.2	43.2	47	54.7	0	0						
2011-03-26 20:10:01	11.3	40.2	42.4	46.9	54.7	0	0						
2011-03-26 20:15:01	11.2	40.2	41.6	46.9	54.5	0	0						
2011-03-26 20:20:01	11.3	40.2	40.6	46.9	54.5	0	0						
2011-03-26 20:25:02	11	40.1	39.3	46.6	54.3	0	0						
2011-03-26 20:30:02	11	40.2	38	46.7	54.2	0	0						
2011-03-26 20:35:01	11	40.3	36.7	46.7	54.2	0	0						
2011-03-26 20:40:01	10.9	40.2	35.9	46.5	54	0	0						
2011-03-26 20:45:01	10.9	40.2	34.6	46.5	53.8	0	0						
2011-03-26 20:50:01	10.7	40.1	33.7	46.4	53.7	0	0						
2011-03-26 2

use this method
String[] rows = File.ReadAllLines("filelocation");
you will get rows in array

Ok thx, and shoud i make to represent the Rows and line with Datagrid???

Yes you'll get the rows in array you split it by "," and add the rows in datagridview!!

File.ReadAllLines("filelocation");???? you mean File.ReadToEnd("filelocation");???? i haave never fund your File.ReadAllLines

But in my case File ist a StreamReader,and don´t acces to this methode ReadAllLines.
report to my code,

string[] Row = Read_File.ReadAllLines(File_Path);

check it my compiler give a fehler back

Ok it is good,that was my mistake thank you....it is possible

No i still have problem with the representation on a Datagrid,may be you can help me

This is code I use in one of my programs:

// read CSV file from LIMS and make a Datatable Object 
        public DataTable BuildDataTable(string fileFullPath, char seperator)
        {
            const int EOF = -1;

            DataTable myTable = new DataTable("MyTable");
            DataRow myRow;
            StreamReader myReader;
            string Title;
            try
            {
                myReader = new StreamReader(fileFullPath);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Fout bij openen bestand: " + ex.Message);
                return new DataTable("Empty");
            }
            try
            // Open file and read first line to determine how many fields there are.
            {
                string[] fieldValues = myReader.ReadLine().Split(new Char[] { seperator, '\t' }); //skip title
                Title = fieldValues[0];
                fieldValues = myReader.ReadLine().Split(new Char[] { seperator, '\t' });
                // Adding the first line of data to data table (columnnames)
                // Create data columns accordingly
                for (int i = 0; i < fieldValues.Length; i++)
                {
                    if (i==0) myTable.Columns.Add(new DataColumn("Code"));
                    else  if (i==1) myTable.Columns.Add(new DataColumn("Datum"));
                    else
                        myTable.Columns.Add(new DataColumn(fieldValues[i].ToString().Trim()));
                }
                //Now reading the rest of the data to data table
                while (myReader.Peek() != EOF)
                {
                    fieldValues = myReader.ReadLine().Split(new Char[] { seperator });
                    myRow = myTable.NewRow();
                    for (int i = 0; i < fieldValues.Length; i++)
                    {
                        myRow[i] = fieldValues[i].ToString().Trim();
                    }
                    myTable.Rows.Add(myRow);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error building datatable: " + ex.Message);
                return new DataTable("Empty");
            }
            finally
            {
                if (myReader != null)
                {
                    myReader.Close();
                }
            }
            myTable.AcceptChanges();
            if (myReader != null)
            {
                myReader.Close();
            }
            return myTable;
        }

Once you have a DataTable use:
MyDataGridView.DataSource = MyDataTable;

hey ddanbe,
i modify your code an aplain it in the file i have joined in my Thread,but it never run,i got a Exception(Erro Building Datatable:a Row '0' is already be in this Datatable.)
Can you help me please????

thx

In my CSV file I had a title, which I don't need in the DGV in this case. Try to remmove Line 22,23 of my code. Hope it helps.

i made it but without Succes, but i still looking for another Solution


Thx ddanbe

What do do you mean by: "I made it but without success" ?
My code was meant for the situation I had to handle, think you can adapt it to yours.

Hey Ddanbe ,th way i try to explain ist that,in my Datagid,my rows don´t contain any values,i have only values in Colums,and in Rows Nothing.that is the way i modify your code,just loók please and tell me what i made wrong,thx in advance

public DataTable BuildDataTable(string fileFullPath, char seperator)   
        {  const int EOF = -1;
            DataTable myTable = new DataTable("MyTable");            
            DataRow myRow;            
            StreamReader myReader = new StreamReader(fileFullPath);            
            string Set_Data = myReader.ReadLine();  
           
            int  Set_len =  Set_Data.Length;
            try            
            {               
               myReader = new StreamReader(fileFullPath);            
            }            
            catch (Exception ex)            
            {                
                MessageBox.Show("Fout bij openen bestand: " + ex.Message);              
                return new DataTable("Empty");          
            }           
            try            
                // Open file and read first line to determine how many fields there are.            
            {
                string[] fieldValues =  new string [Set_len];//myReader.ReadLine().Split(new Char[] { seperator, '\t' }); 
                //skip title               
               // Title = fieldValues[2];               
                fieldValues = myReader.ReadLine().Split(new Char[] { seperator, '\t' });                
                // Adding the first line of data to data table (columnnames)                
                // Create data columns accordingly                
                for (int i = 0; i < fieldValues.Length; i++)               
                {                    
                    //if (i==0) myTable.Columns.Add(new DataColumn("Code"));                   
                 
                     //if (i==1) myTable.Columns.Add(new DataColumn("Datum"));                  
                     myTable.Columns.Add(new DataColumn(fieldValues[i].ToString().Trim()));              
                }               
                //Now reading the rest of the data to data table               
                while (myReader.Peek() != EOF)               
                {                   
                    fieldValues = myReader.ReadLine().Split(new Char[] { seperator });                  
                    myRow = myTable.NewRow();                    
                    for (int i = 0; i < fieldValues.Length; i++)                   
                    {                      
                        myRow[i] = fieldValues[i].ToString().Trim();
                       
                    }
                    myTable.Rows.Add(myRow);         
                }          
            }           
            catch (Exception ex)           
            {               
                MessageBox.Show("Error building datatable: " + ex.Message);               
                return new DataTable("Empty");           
            }            
            finally         
            {               
                if (myReader != null)               
                {                  
                    myReader.Close();               
                }            
            }            
            myTable.AcceptChanges();           
            if (myReader != null)          
            {               
                myReader.Close();           
            }
            dataGridView1.DataSource = myTable;
            return myTable;       
        }

i have only values in Colums,and in Rows Nothing

Could you give an example of your CSV file?
Also, my method returns a DataTable, so line 64 should happen outside the method.

OK, this is what I came up with, hope it helps.
Started a forms app, dropped in a datagridview and a button.
Here is the code and a screenshot:

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();            
        }

        private void button1_Click(object sender, EventArgs e)
        {
            ProcesFile();
        }

        public void ProcesFile() // use this code in a button or menu or both
        {
            DataTable DT;
            OpenFileDialog openFileDialog1 = new OpenFileDialog();

            openFileDialog1.InitialDirectory = "c:\\";
            openFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
            openFileDialog1.FilterIndex = 2;
            openFileDialog1.RestoreDirectory = true;

            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                DT = BuildDataTable(openFileDialog1.FileName,'\t');
                this.dataGridView1.DataSource = DT;
            }
        }

         public DataTable BuildDataTable(string fileFullPath, char seperator)        
         {            
             const int EOF = -1;             
             DataTable myTable = new DataTable("MyTable");            
             DataRow myRow;            
             StreamReader myReader;            
             try            
             {                
                 myReader = new StreamReader(fileFullPath);            
             }            
             catch (Exception ex)            
             {                
                 MessageBox.Show("Fehler beim ofnen: " + ex.Message);   // :o)             
                 return new DataTable("Empty");            
             }
             try            
                 // Open file and read first line to determine how many fields there are.            
             {
                 string[] fieldValues = myReader.ReadLine().Split(new Char[] { seperator });                
                 // Adding the first line of data to data table (columnnames)                
                 // Create data columns accordingly                
                 for (int i = 0; i < fieldValues.Length; i++)                
                 {                                          
                    myTable.Columns.Add(new DataColumn(fieldValues[i].ToString().Trim()));  
                 }
                 //Now reading the rest of the data to the data table                
                 while (myReader.Peek() != EOF)                
                 {                    
                     fieldValues = myReader.ReadLine().Split(new Char[] { seperator });          
                     myRow = myTable.NewRow();                    
                     for (int i = 0; i < fieldValues.Length; i++)  //fill a row with values                  
                     {                        
                         myRow[i] = fieldValues[i].ToString().Trim();                    
                     }                    
                     myTable.Rows.Add(myRow);                
                 }            
             }
             catch (Exception ex)
             {
                 MessageBox.Show("Error building datatable: " + ex.Message);
                 return new DataTable("Empty");
             }
             finally
             {
                 if (myReader != null)
                 {
                     myReader.Close();
                 }
             }
             myTable.AcceptChanges();
             if (myReader != null)
             {
                 myReader.Close();
             }
             return myTable;
         }
    }
}

Happy computing!

Attachments Wasser.jpg 56.8 KB
This question has already been answered. Start a new discussion instead.