const string dataPath = @"D:Usersjin_hDocumentsVisual Studio 2013ProjectsConsoleApplication1ConsoleApplication1";
private static DataTable GetCsvData(string filePath, string fileName) { string connString = @"Driver={Microsoft Text Driver (*.txt; *.csv)};Dbq=" + filePath + ";Extensions=asc,csv,tab,txt;"; try { using (var odbcConn = new OdbcConnection(connString)) { odbcConn.Open(); var oleComm = new OdbcCommand(); oleComm.Connection = odbcConn; oleComm.CommandText = "select * from [" + fileName + "#csv]"; var adapter = new OdbcDataAdapter(oleComm); var ds = new DataSet(); adapter.Fill(ds, fileName); return ds.Tables[0]; } } catch (Exception ex) { throw ex; } } private static string ExportCSV(IEnumerable<ErrorData> errorDate) { var sbBuilder = new StringBuilder(); string[] title = { "ScenciSpotID", "DistrictNamePath", "GeographicRegionKeyword", "NoMatchField" }; foreach (var t in title) { sbBuilder.Append(t + ","); } sbBuilder.Append(" "); foreach (var field in errorDate) { sbBuilder.Append(field.ScenciSpotID + ","); sbBuilder.Append(field.DistrictNamePath + ","); sbBuilder.Append(field.GeographicRegionKeyword + ","); sbBuilder.Append(field.NoMatchField + ","); sbBuilder.Append(" "); } return sbBuilder.ToString(); }