csv - C# - Trouble reading a tab delimited file using Microsoft Jet OLEDB -
csv - C# - Trouble reading a tab delimited file using Microsoft Jet OLEDB -
i trying read excel .csv file tab delimited. there's 8 columns mixed info in each. post image of output don't have plenty reputation (this first post, bear me). essentially, output table dt contains single column gibberish column heading.
here code using:
from app.config:
<add key="cnprovider" value="microsoft.jet.oledb.4.0"/> <add key="cnproperties" value=""text;hdr=yes;fmt=tabdelimited;characterset=65001""/> from program.cs:
string sqlstatement_1 = configurationsettings.appsettings["sqlstatement_1"]; string cnproperties = configurationsettings.appsettings["cnproperties"]; string cnstr = "provider=" + cnprovider + ";data source=" + folder + ";extended properties=" + cnproperties + ";"; oledbdataadapter adp; adp = new oledbdataadapter(sqlstatement_1, cnstr); using (adp) { adp.fill(dt); } this code worked fine on comma-delimited file when changing fmt delimited instead of tabdelimited. ideas? file size less 1000 lines, execution speed not big deal. code not produce exceptions.
thanks in advance!
i wasn't able jet driver work - suspect there's non-standard .csv file. anyway, solution, works well. 1 time again responded.
public static datatable readcsv() { //create info table , add together column's datatable table = new datatable("table_name"); int = 0; table.columns.add("city", typeof(string)); table.columns.add("owner", typeof(string)); table.columns.add("unit_number", typeof(string)); table.columns.add("equipment_desc", typeof(string)); table.columns.add("wo_type", typeof(string)); table.columns.add("wo_number", typeof(string)); table.columns.add("wo_desc", typeof(string)); table.columns.add("wo_status", typeof(string)); table.columns.add("days_oos", typeof(string)); //start reading textfile streamreader reader = new streamreader(@"c:\...\...csv"); string line; while ((line = reader.readline()) != null) { if (i == 0) { //skip headings } else { string[] items = line.split('\t'); //make sure has 3 items if (items.length == 9) { datarow row = table.newrow(); row["city"] = items[0]; row["owner"] = items[1]; row["unit_number"] = items[2]; row["equipment_desc"] = items[3]; row["wo_type"] = items[4]; row["wo_number"] = items[5]; row["wo_desc"] = items[6]; row["wo_status"] = items[7]; row["days_oos"] = items[8]; table.rows.add(row); } } i++; } reader.close(); reader.dispose(); // create utilize of table homecoming table; } c# csv datatable oledb delimited
Comments
Post a Comment