/// <summary> /// Import delimited text file service. /// </summary> /// <param name="fileName">CSV File to Import </param> /// <returns>imported datatable</returns> public List<string> ImportDelimited(string fileName) { StreamReader sr = null; List<string> list = new List<string>(); try { sr = new StreamReader(fileName); while (!sr.EndOfStream) { list.Add(sr.ReadLine()); } } catch (Exception e) { throw e; } finally { sr.Close(); } return list; }this is a sample import from a compact app I have:
/// <summary> /// Load thing data to SQL /// </summary> /// <param name="fileName">CSV File to Import </param> public void LoadThingDataToSQL(string fileName) { _dtThing = new ThingDataSet.ThingsDataTable(); ThingDataSet.ThingsRow dr = null; try { BDImportService bis = new BDImportService(); List<string> list = bis.ImportDelimited(fileName); foreach (string s in list) { string[] sa = s.Split(",".ToCharArray()); dr = _dtThing.NewThingsRow(); //were grabbing the taxonomy name here, we'll translate the foreign keys //in another step. dr.Taxonomy = sa[_dtThing.TaxonomyColumn.Ordinal - 1]; dr.Name = sa[_dtThing.NameColumn.Ordinal - 1]; dr.Seen = Convert.ToBoolean(sa[_dtThing.SeenColumn.Ordinal-1].Equals("0") ? false : true); dr.CommonName = sa[_dtThing.CommonNameColumn.Ordinal-1]; dr.ScientificName = sa[_dtThing.ScientificNameColumn.Ordinal-1]; dr.SortOrder = (float)(Convert.ToDecimal(sa[_dtThing.SortOrderColumn.Ordinal - 1])); _dtThing.AddThingsRow(dr); } this.UpdateThingTable(_dtThing); } catch (Exception e) { throw e; } }Hope this helps....