Below is an example text file
{
Here is my schema file
[Sample File.txt]
ColNameHeader=True
Format=TabDelimited
CharacterSet=ANSI
And here is the code that I have written so far to try and read the above example file, the data lines read from the text file above should be returned for display in the dataGridView control. The problem is that it returns as a single column, but I want to use these spaces as column separators. I tried different character delimiters without success.
public DataSet LoadCSV(int numberOfRows)
{
DataSet ds = new DataSet();
string strConnString = "Driver={Microsoft Text Driver (*.txt; *.csv)};Dbq=" + this.dirCSV.Trim() + ";Extensions=asc,csv,tab,txt;Persist Security Info=False";
string sql_select;
OdbcConnection conn;
conn = new OdbcConnection(strConnString.Trim());
conn.Open();
if (numberOfRows == -1)
{
sql_select = "select * from [" + this.FileNevCSV.Trim() + "]";
}
else
{
sql_select = "select top " + numberOfRows + " * from [" + this.FileNevCSV.Trim() + "]";
}
OdbcDataAdapter obj_oledb_da = new OdbcDataAdapter(sql_select, conn);
obj_oledb_da.Fill(ds, "csv");
conn.Close();
return ds;
}
And setting the dataGridView data source as
this.dataGridView_preView.DataSource = LoadCSV(500);
this.dataGridView_preView.DataMember = "csv";
i get this in a datagridview, i get one column, but i expect to see the data returned as 7 columns.
Plus, I have no idea where the columns F2 and F3 come from
