// <Snippet1> private static void TestGetValues(DataTableReader reader) { // Given a DataTableReader, use the GetValues // method to retrieve a full row of data. // Test the GetValues method, passing in an array large // enough for all the columns. Object[] values = new Object[reader.FieldCount]; int fieldCount = reader.GetValues(values); Console.WriteLine("reader.GetValues retrieved {0} columns.", fieldCount); for (int i = 0; i < fieldCount; i++) { Console.WriteLine(values[i]); } Console.WriteLine(); // Now repeat, using an array that may contain a different // number of columns than the original data. This should work correctly, // whether the size of the array is larger or smaller than // the number of columns. // Attempt to retrieve three columns of data. values = new Object[3]; fieldCount = reader.GetValues(values); Console.WriteLine("reader.GetValues retrieved {0} columns.", fieldCount); for (int i = 0; i < fieldCount; i++) { Console.WriteLine(values[i]); } }
public void GetProviderSpecificTests() { DataTableReader rdr = dt.CreateDataReader (); while (rdr.Read ()) { object[] values = new object [rdr.FieldCount]; object[] pvalues = new object [rdr.FieldCount]; rdr.GetValues (values); rdr.GetProviderSpecificValues (pvalues); for (int i = 0; i < rdr.FieldCount; ++i) { Assert.AreEqual(values [i], pvalues [i], "#1"); Assert.AreEqual(rdr.GetValue (i), rdr.GetProviderSpecificValue (i), "#2"); Assert.AreEqual(rdr.GetFieldType (i), rdr.GetProviderSpecificFieldType (i), "#3"); } } }
/// <summary> /// Imports article from csv file to db. If article with same number exists, it will be replaced. /// </summary> /// <param name="db"></param> /// <param name="file"></param> /// <returns></returns> public static bool ImportArticleFromCsv(ISposDb db, string file) { // read csv file DataTable data = ParseCSV(file); if (data == null) { return(false); } // convert data DataTableReader reader = new DataTableReader(data); if (reader.FieldCount != 5 && !reader.HasRows) { return(false); } List <SimplePOS.Article.RegularArticle> articleList = new List <SimplePOS.Article.RegularArticle>(); reader.Read(); // read the header while (reader.Read()) { object[] values = new object[5]; int result = reader.GetValues(values); if (result > 0) { try { // Text may be empty wich results in a strange object string text; try { text = (string)values[2]; } catch { text = ""; } articleList.Add(new SimplePOS.Article.RegularArticle((string)values[0], (string)values[1], text, Double.Parse((string)values[3]), Double.Parse((string)values[4]))); } catch { return(false); } } } // import to db db.SaveArticleList(articleList); return(true); }
public List <T> Map(DataTable dataTable) { List <T> entities = new List <T>(); using (DataTableReader reader = dataTable.CreateDataReader()) { Object[] values = new object[reader.FieldCount]; while (reader.Read()) { reader.GetValues(values); T entity = Activator.CreateInstance <T>(); for (int i = 0; i < reader.FieldCount; i++) { MapPrimative(values[i], reader.GetName(i), entity); } entities.Add(entity); } } return(entities); }
public int GetValues(object[] values) { return(_reader.GetValues(values)); }