private static void TestCreateDataReader(DataSet dataSet) { // Given a DataSet, retrieve a DataTableReader // allowing access to all the DataSet's data. // Even though the dataset contains three DataTables, // this code will only display the contents of two of them, // because the code has limited the results to the // DataTables stored in the tables array. Because this // parameter is declared using the ParamArray keyword, // you could also include a list of DataTable instances // individually, as opposed to supplying an array of // DataTables, as in this example: using (DataTableReader reader = dataSet.CreateDataReader(productTable, emptyTable)) { do { if (!reader.HasRows) { Console.WriteLine("Empty DataTableReader"); } else { PrintColumns(reader); } Console.WriteLine("========================"); } while (reader.NextResult()); } }
public void MultipleResultSetsTest() { DataTable dt1 = new DataTable("test2"); dt1.Columns.Add("x", typeof(string)); dt1.Rows.Add(new object[] { "test" }); dt1.Rows.Add(new object[] { "test1" }); dt1.AcceptChanges(); DataTable[] collection = new DataTable[] { _dt, dt1 }; DataTableReader reader = new DataTableReader(collection); try { int i = 0; do { while (reader.Read()) { i++; } } while (reader.NextResult()); Assert.Equal(5, i); } finally { if (reader != null && !reader.IsClosed) { reader.Close(); } } }
public void SchemaTest() { DataTable another = new DataTable("another"); another.Columns.Add("x", typeof(string)); another.Rows.Add(new object[] { "test 1" }); another.Rows.Add(new object[] { "test 2" }); another.Rows.Add(new object[] { "test 3" }); DataTableReader reader = new DataTableReader(new DataTable[] { _dt, another }); try { DataTable schema = reader.GetSchemaTable(); Assert.Equal(_dt.Columns.Count, schema.Rows.Count); Assert.Equal(_dt.Columns[1].DataType.ToString(), schema.Rows[1]["DataType"].ToString()); reader.NextResult(); //schema should change here schema = reader.GetSchemaTable(); Assert.Equal(another.Columns.Count, schema.Rows.Count); Assert.Equal(another.Columns[0].DataType.ToString(), schema.Rows[0]["DataType"].ToString()); } finally { if (reader != null && !reader.IsClosed) { reader.Close(); } } }
public LinkedList <Sale> selectSalesReport() { LinkedList <Sale> sales = new LinkedList <Sale>(); DataTable dataSales = sda.selectSalesReport(); DataTableReader reader = dataSales.CreateDataReader(); int status = 0; int delivery = 0; do { if (reader.HasRows) { while (reader.Read()) { if (bool.Parse(reader[6].ToString())) { status = 1; } if (bool.Parse(reader[8].ToString())) { delivery = 1; } Sale sale = new Sale(int.Parse(reader[0].ToString()), reader[1].ToString(), int.Parse(reader[2].ToString()), int.Parse(reader[3].ToString()), int.Parse(reader[4].ToString()), reader[5].ToString(), status, DateTime.Parse(reader[7].ToString()), delivery); sales.AddLast(sale); } } } while (reader.NextResult()); return(sales); }
private static List <string> GetTableNames(string connectionStr) { using (OdbcConnection connection = new OdbcConnection(connectionStr)) { connection.Open(); var names = new List <string>(); System.Data.DataTable dataTable = connection.GetSchema("Tables"); // Columns for "Tables" table: TABLE_CAT, TABLE_SCHEM, TABLE_NAME, TABLE_TYPE, REMARKS DataTableReader dtr = new DataTableReader(dataTable); do { while (dtr.Read()) { if ((string)dtr["TABLE_TYPE"] == "TABLE") { var name = dtr["TABLE_NAME"]; if (name.GetType() == typeof(System.String)) { names.Add((string)name); } else { Console.WriteLine("Weird stuff is going on. Investigate!"); } } } } while (dtr.NextResult()); return(names); } }
//use to work with an existing datatable timestamp public virtual TimeSpan DetectInterval() { //determines the interval by selecting the interval with the greatest occurrence try { DataView view = _data.AsDataView(); view.Sort = Settings.Default.TimeStampName + " asc"; //count each interval occurence TimeSpan gap = default(TimeSpan); DateTime prevVal = default(DateTime); DateTime curVal = default(DateTime); DataTableReader reader = new DataTableReader(_data); Dictionary <TimeSpan, int> resultCount = new Dictionary <TimeSpan, int>(); reader.NextResult(); //create table of counts grouped by gap while (reader.Read()) { curVal = (DateTime)reader[_dateIndex]; if (prevVal != default(DateTime)) { gap = curVal - prevVal; if (resultCount.ContainsKey(gap)) { resultCount[gap] += 1; } else { resultCount.Add(gap, 1); } } prevVal = curVal; } //determine the gap with the greatest count int workval = 0; int maxval = 0; TimeSpan greatest = default(TimeSpan); foreach (KeyValuePair <TimeSpan, int> kv in resultCount) { workval = kv.Value; if (workval > maxval) { maxval = workval; greatest = kv.Key; } } return(greatest); } catch (Exception e) { throw e; } }
public void NoRowsTest () { dt.Rows.Clear (); dt.AcceptChanges (); DataTableReader reader = new DataTableReader (dt); try { Assert.IsFalse (reader.Read (), "#1 there are no rows"); Assert.IsFalse (reader.NextResult (), "#2 there are no further resultsets"); } finally { if (reader != null && !reader.IsClosed) reader.Close (); } }
private void BtnListing_Click(object sender, RoutedEventArgs e) { DataTableReader dtr = dsAuto.CreateDataReader(); LstArtikel.Items.Add("LIJST VAN VERKOPERS"); while (dtr.Read()) { LstArtikel.Items.Add(dtr["Naam"]); } //Naar volgende tabel. dtr.NextResult(); LstArtikel.Items.Add(""); LstArtikel.Items.Add("LIJST VAN AUTO'S"); while (dtr.Read()) { LstArtikel.Items.Add(dtr["Beschrijving"]); } }
public LinkedList <int> clientReadyTransportLink() { LinkedList <int> sales = new LinkedList <int>(); DataTable dataSales = sda.clientReadyTransport(); DataTableReader reader = dataSales.CreateDataReader(); do { if (reader.HasRows) { while (reader.Read()) { sales.AddLast(int.Parse(reader[0].ToString())); } } } while (reader.NextResult()); return(sales); }
public LinkedList <Product> getProductLinkSales() { LinkedList <Product> products = new LinkedList <Product>(); DataTable dataProduct = pda.selectProductSales(); DataTableReader reader = dataProduct.CreateDataReader(); do { if (reader.HasRows) { while (reader.Read()) { Product product = new Product(int.Parse(reader[0].ToString()), reader[1].ToString(), int.Parse(reader[4].ToString()), int.Parse(reader[5].ToString())); products.AddLast(product); } } } while (reader.NextResult()); return(products); }
public LinkedList <Transport> getTransportLink() { LinkedList <Transport> transports = new LinkedList <Transport>(); DataTable dataTransport = tda.selectTransport(); DataTableReader reader = dataTransport.CreateDataReader(); do { if (reader.HasRows) { while (reader.Read()) { Transport transport = new Transport(int.Parse(reader[0].ToString()), reader[1].ToString(), int.Parse(reader[2].ToString())); transports.AddLast(transport); } } } while (reader.NextResult()); return(transports); }
public LinkedList <Service> getServLink() { LinkedList <Service> serv = new LinkedList <Service>(); DataTable dataService = sev.selectServ(); DataTableReader reader = dataService.CreateDataReader(); do { if (reader.HasRows) { while (reader.Read()) { Service servi = new Service(int.Parse(reader[0].ToString()), reader[1].ToString(), reader[2].ToString(), reader[3].ToString(), int.Parse(reader[4].ToString())); serv.AddLast(servi); } } } while (reader.NextResult()); return(serv); }
public LinkedList <string> selectSalesReportCatProduct() { LinkedList <string> sales = new LinkedList <string>(); DataTable dataSales = sda.selectSalesReportCatProduct(); DataTableReader reader = dataSales.CreateDataReader(); do { if (reader.HasRows) { while (reader.Read()) { string obj = reader[1].ToString(); sales.AddLast(obj); } } } while (reader.NextResult()); return(sales); }
public LinkedList <User> getClientsLink() { LinkedList <User> users = new LinkedList <User>(); DataTable dataUsers = uda.selectClients(); DataTableReader reader = dataUsers.CreateDataReader(); do { if (reader.HasRows) { while (reader.Read()) { User user = new User(int.Parse(reader[0].ToString()), int.Parse(reader[1].ToString()), reader[2].ToString(), reader[3].ToString(), reader[4].ToString()); users.AddLast(user); } } } while (reader.NextResult()); return(users); }
public LinkedList <string> selectTransportStatusLink() { LinkedList <string> transports = new LinkedList <string>(); DataTable dataTransport = tda.selectTransportStatus(); DataTableReader reader = dataTransport.CreateDataReader(); do { if (reader.HasRows) { while (reader.Read()) { string dats = reader[0].ToString(); transports.AddLast(dats); } } } while (reader.NextResult()); return(transports); }
public LinkedList <Sale> getSaleLinkPay() { LinkedList <Sale> sales = new LinkedList <Sale>(); DataTable dataSales = sda.selectSalePayment(); DataTableReader reader = dataSales.CreateDataReader(); do { if (reader.HasRows) { while (reader.Read()) { Sale sale = new Sale(int.Parse(reader[0].ToString()), reader[1].ToString(), int.Parse(reader[2].ToString()), int.Parse(reader[3].ToString()), int.Parse(reader[4].ToString()), reader[5].ToString(), int.Parse(reader[6].ToString()), DateTime.Parse(reader[7].ToString()), int.Parse(reader[8].ToString())); sales.AddLast(sale); } } } while (reader.NextResult()); return(sales); }
public void NoRowsTest() { _dt.Rows.Clear(); _dt.AcceptChanges(); DataTableReader reader = new DataTableReader(_dt); try { Assert.False(reader.Read()); Assert.False(reader.NextResult()); } finally { if (reader != null && !reader.IsClosed) { reader.Close(); } } }
// <Snippet1> private static void TestHasRows() { DataTable customerTable = GetCustomers(); DataTable productTable = GetProducts(); using (DataTableReader reader = new DataTableReader( new DataTable[] { customerTable, productTable })) { do { if (reader.HasRows) { PrintData(reader); } } while (reader.NextResult()); } Console.WriteLine("Press Enter to finish."); Console.ReadLine(); }
private static void TestCreateDataReader(DataTable dt) { // Given a DataTable, retrieve a DataTableReader // allowing access to all the tables' data: using (DataTableReader reader = dt.CreateDataReader()) { do { if (!reader.HasRows) { Console.WriteLine("Empty DataTableReader"); } else { PrintColumns(reader); } Console.WriteLine("========================"); } while (reader.NextResult()); } }
// <Snippet1> private static void TestConstructor() { // Create two data adapters, one for each of the two // DataTables to be filled. DataTable customerDataTable = GetCustomers(); DataTable productDataTable = GetProducts(); // Create the new DataTableReader. using (DataTableReader reader = new DataTableReader( new DataTable[] { customerDataTable, productDataTable })) { // Print the contents of each of the result sets. do { PrintColumns(reader); } while (reader.NextResult()); } Console.WriteLine("Press Enter to finish."); Console.ReadLine(); }
public bool NextResult() { return(_reader.NextResult()); }
public void NoRowsTest() { _dt.Rows.Clear(); _dt.AcceptChanges(); DataTableReader reader = new DataTableReader(_dt); try { Assert.False(reader.Read()); Assert.False(reader.NextResult()); } finally { if (reader != null && !reader.IsClosed) reader.Close(); } }
public void MultipleResultSetsTest() { DataTable dt1 = new DataTable("test2"); dt1.Columns.Add("x", typeof(string)); dt1.Rows.Add(new object[] { "test" }); dt1.Rows.Add(new object[] { "test1" }); dt1.AcceptChanges(); DataTable[] collection = new DataTable[] { _dt, dt1 }; DataTableReader reader = new DataTableReader(collection); try { int i = 0; do { while (reader.Read()) i++; } while (reader.NextResult()); Assert.Equal(5, i); } finally { if (reader != null && !reader.IsClosed) reader.Close(); } }
public void SchemaTest() { DataTable another = new DataTable("another"); another.Columns.Add("x", typeof(string)); another.Rows.Add(new object[] { "test 1" }); another.Rows.Add(new object[] { "test 2" }); another.Rows.Add(new object[] { "test 3" }); DataTableReader reader = new DataTableReader(new DataTable[] { _dt, another }); try { DataTable schema = reader.GetSchemaTable(); Assert.Equal(_dt.Columns.Count, schema.Rows.Count); Assert.Equal(_dt.Columns[1].DataType.ToString(), schema.Rows[1]["DataType"].ToString()); reader.NextResult(); //schema should change here schema = reader.GetSchemaTable(); Assert.Equal(another.Columns.Count, schema.Rows.Count); Assert.Equal(another.Columns[0].DataType.ToString(), schema.Rows[0]["DataType"].ToString()); } finally { if (reader != null && !reader.IsClosed) reader.Close(); } }