How to read CSV file
-
HOw i Display CSV File Data TO DataGridView Please Help me With Connection string And Code.
-
HOw i Display CSV File Data TO DataGridView Please Help me With Connection string And Code.
Hi!!! Try to do some research by yourself instead of asking code from others.... have a look at this site.... csv to datatable[^] Can give you some insight regarding the issue....
Have a Happy Coding.....
-
Hi!!! Try to do some research by yourself instead of asking code from others.... have a look at this site.... csv to datatable[^] Can give you some insight regarding the issue....
Have a Happy Coding.....
I have tried it But i got Error Path is not correct even i give it to right path here is my code string Con_Str = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\My\a.csv;Extended Properties=Text;HDR=No;FMT=Delimited"; OleDbConnection cn = new OleDbConnection(Con_Str); cmd=new OleDbCommand("select * from Book1.CSV",cn ); da=new OleDbDataAdapter(cmd); ds=new DataSet(); da.Fill(ds,"ex"); dataGridView1.DataSource=ds.Tables[0].DefaultView;
-
HOw i Display CSV File Data TO DataGridView Please Help me With Connection string And Code.
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Reflection; using System.Runtime.InteropServices; using Excel = Microsoft.Office.Interop.Excel; using System.Data.OleDb; using System.Security.Cryptography; public DataSet ExcelToDS(string Path) { //return one dataset object missing = Missing.Value; Excel.Application excelApp = new Excel.Application(); excelApp.Visible = false; try { excelApp.Workbooks.Open(path, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing); excelApp.Workbooks[1].Worksheets[i + 1]; Excel.Worksheet ws = (Excel.Worksheet)excelApp.Workbooks[1].Worksheets[1]; string sheetName = ws.Name; string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + Path + ";" + "Extended Properties=Excel 8.0;"; OleDbConnection conn = new OleDbConnection(strConn); conn.Open(); string strExcel = ""; OleDbDataAdapter myCommand = null; DataSet ds = null; strExcel = "select * from [" + sheetName + "$]"; myCommand = new OleDbDataAdapter(strExcel, strConn); ds = new DataSet(); myCommand.Fill(ds); conn.Close(); excelApp.Workbooks.Close(); excelApp.Quit(); excelApp = null; return ds; } catch { MessageBox.Show("Not close EXCEL", "Err Info", MessageBoxButtons.OKCancel, MessageBoxIcon.Error); KillProcess("EXCEL"); return null; } }
modified on Tuesday, May 5, 2009 3:52 AM
-
I have tried it But i got Error Path is not correct even i give it to right path here is my code string Con_Str = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\My\a.csv;Extended Properties=Text;HDR=No;FMT=Delimited"; OleDbConnection cn = new OleDbConnection(Con_Str); cmd=new OleDbCommand("select * from Book1.CSV",cn ); da=new OleDbDataAdapter(cmd); ds=new DataSet(); da.Fill(ds,"ex"); dataGridView1.DataSource=ds.Tables[0].DefaultView;
So what's the filename of your CSV file?? In your code you have, in the connection string, C:\My\a.csv. But, in the OleDbCommand, you have Book1.CSV. So, which is it??
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007, 2008