June 26, 2017

Import .csv file into datatable and populate the datagridview

DataTable dt = new DataTable();
            dt.Columns.Add("barcode", System.Type.GetType("System.String"));
            System.IO.StreamReader csv_file = File.OpenText("D:\\Barcode_Generated_File.csv");

            while (csv_file.Peek() >= 0)
            {
                string line = objED.Decrypt_data(csv_file.ReadLine());
                string line1 = line.Remove(line.Length - 1);
                string[] vals = line1.Split(';');
                DataRow dr = dt.NewRow();
                dr["barcode"] = vals[0];
                dt.Rows.Add(dr);
            }
            csv_file.Close();

            grdSerialNo.DataSource = dt;
            grdSerialNo.Columns[0].Width = 790; 

No comments:

Post a Comment