// Draw Pants based on type Pants private void drawPants(Product p) { Pants pants = (Pants)p; drawSet(true, true, true, true, true, false, false, false); drawApparel(p); lblVar4.Text = "Waist"; txtVar4.Text = pants.Waist.ToString(); lblVar5.Text = "Inseam"; txtVar5.Text = pants.Inseam.ToString(); }
// This method accepts an id and returns the Pants table entry that // matches the id public static Pants SelectPants(string id) { // Set p to null Pants p = null; // Get a connection to DB OleDbConnection connection = GetConnection(); // Create a query string string select = "SELECT Product.ID, Product.Desc, Product.Price, " + "Product.Qty, Product.Type, Apparel.Material, Apparel.Color, Apparel.Manufacturer, " + "Pants.Waist, Pants.Inseam FROM (Product INNER JOIN Apparel ON Product.ID = Apparel.ID)" + "INNER JOIN Pants ON Apparel.ID = Pants.ID WHERE Product.ID = '" + id + "';"; // Declare and instantiate a command object OleDbCommand command = new OleDbCommand(select, connection); try { // Open connection connection.Open(); // Use command to execute a query with results in reader OleDbDataReader reader = command.ExecuteReader(); if (reader.Read()) { // Instantiate and copy data from reader p = new Pants(); p.ID = reader.GetString(0); p.Desc = reader.GetString(1); p.Price = reader.GetDouble(2); p.Qty = reader.GetInt32(3); p.Type = reader.GetString(4); p.Material = reader.GetString(5); p.Color = reader.GetString(6); p.Manufacturer = reader.GetString(7); p.Waist = reader.GetInt32(8); p.Inseam = reader.GetInt32(9); } } catch (Exception ex) { MessageBox.Show(ex.ToString()); p = null; // In case the complete record was not successfully copied } finally { // Close connection connection.Close(); } // Will contain a Pant if found and null if not return(p); }