c# - Import Headerless CSV into Data Grid View using first row as header -


i have following code pulls data csv file specified user. csv file without headers , has 4 columns of data. i'm trying import data datagridview datasource, unexpected results. each time, takes first row , makes header column. tried inserting row @ beginning (commented out text), add row datasource, not treat header. i'm not worried having headers, data not "omit" first row since sees header.

string sql_select; string strconnstring = "driver={microsoft text driver (*.txt; *.csv)};dbq=" + path.getdirectoryname(odfdeficit.filename).trim() + ";extensions=asc,csv,tab,txt"; dataset ds = new dataset(); odbcconnection conn = new odbcconnection(strconnstring.trim()); sql_select = "select * [" + path.getfilename(odfdeficit.filename).trim() + "]"; odbcdataadapter obj_oledb_da = new odbcdataadapter(sql_select, conn); obj_oledb_da.fill(ds, "csv");  //datarow dr; //dr = ds.tables["csv"].newrow(); //dr[0] = "first name"; //dr[1] = "last name"; //dr[2] = "last 4 of ssn"; //dr[3] = "deficit amount"; //ds.tables["csv"].rows.insertat(dr, 0); datagridview1.datasource = ds.tables["csv"]; conn.close(); 

have tried explicitly creating columns table, , loading table csv file?

datatable csvtable = new datatable();  csvtable.columns.add("firstname", typeof(string)); csvtable.columns.add("lastname", typeof(string)); csvtable.columns.add("lastfourofssn", typeof(string)); csvtable.columns.add("deficitamount", typeof(string));  obj_oledb_da.fill(csvtable);  datagridview1.datasource = csvtable; 

i can't work, it's worth try.

also, out of curiosity, why using odbc? use oledb or microsoft.visualbasic.fileio.textfieldparser class. i'm not saying odbc wrong, presenting couple of alternative ways.


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -