private void button2_Click(object sender, EventArgs e) { //This code is for validating the csv file and filling the rows in the grid. string Path; Path = lblfilepath.Text; dataGridView1.DataSource = ReadCSV(Path); //Please help me here } private DataTable ReadCSV(string Filename) { string MyPath = System.IO.Path.GetDirectoryName(Filename); string ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + MyPath + ";Extended Properties='text;HDR=Yes;FMT=Delimited'"; String todaysdate; todaysdate = DateTime.Today.ToString() ; string CmdText = "select * from " + System.IO.Path.GetFileName(Filename); OleDbConnection Con = new OleDbConnection(ConnectionString); OleDbDataAdapter adptr = new OleDbDataAdapter(CmdText, Con); //OleDbCommand Cmd = new OleDbCommand(CmdText + txtFileName.Text, Con); DataSet Ds = new DataSet(); adptr.Fill(Ds); return Ds.Tables[0]; }
foreach (DataRow x in dataGridView1.Rows) { //access data either way: x.Field<>(); x.ItemArray; }
dataGridView1.Rows
DataRow
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)