protected void Page_Load(object sender, EventArgs e) { NorthwindTableAdapters.ProductsTableAdapter productsAdapter = new NorthwindTableAdapters.ProductsTableAdapter(); // Add a new product int new_productID = Convert.ToInt32(productsAdapter.InsertProduct("New Product", 1, 1, "12 tins per carton", 14.95m, 10, 0, 10, false)); // On second thought, delete the product productsAdapter.Delete(new_productID); }
protected void Page_Load(object sender, EventArgs e) { NorthwindTableAdapters.ProductsTableAdapter productsAdapter = new NorthwindTableAdapters.ProductsTableAdapter(); Northwind.ProductsDataTable products = productsAdapter.GetProducts(); foreach (Northwind.ProductsRow product in products) { Response.Write("Product: " + product.ProductName + "<br />"); } }
protected void Page_Load(object sender, EventArgs e) { NorthwindTableAdapters.ProductsTableAdapter productsAdapter = new NorthwindTableAdapters.ProductsTableAdapter(); // Delete the product with ProductID 3 productsAdapter.Delete(3); // Update Chai (ProductID of 1), setting the UnitsOnOrder to 15 productsAdapter.Update("Chai", 1, 1, "10 boxes x 20 bags", 18.0m, 39, 15, 10, false, 1); // Add a new product productsAdapter.Insert("New Product", 1, 1, "12 tins per carton", 14.95m, 15, 0, 10, false); }
// OPTIONAL: Use the ItemDataBound event handler approach to retrieve information about // how many products there are for the category without having to modify the DAL protected void Categories_ItemDataBound(object sender, RepeaterItemEventArgs e) { // Make sure we're working with a data item... if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) { // Reference the CategoriesRow instance bound to this RepeaterItem Northwind.CategoriesRow category = (Northwind.CategoriesRow)((System.Data.DataRowView)e.Item.DataItem).Row; // Determine how many products are in this category NorthwindTableAdapters.ProductsTableAdapter productsAPI = new NorthwindTableAdapters.ProductsTableAdapter(); int productCount = productsAPI.GetProductsByCategoryID(category.CategoryID).Count; // Reference the ViewCategory LinkButton and set its Text property LinkButton ViewCategory = (LinkButton)e.Item.FindControl("ViewCategory"); ViewCategory.Text = string.Format("{0} ({1:N0})", category.CategoryName, productCount); } }
protected void Page_Load(object sender, EventArgs e) { NorthwindTableAdapters.ProductsTableAdapter productsAdapter = new NorthwindTableAdapters.ProductsTableAdapter(); // For each product, double its price if it is not discontinued and // there are 25 items in stock or less Northwind.ProductsDataTable products = productsAdapter.GetProducts(); foreach (Northwind.ProductsRow product in products) { if (!product.Discontinued && product.UnitsInStock <= 25) { product.UnitsInStock *= 2; } } // Update the products productsAdapter.Update(products); }
/// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InitializeComponent() { string resourceFileName = "XtraReport1.resx"; this.Detail = new DevExpress.XtraReports.UI.DetailBand(); this.xrPictureBox1 = new DevExpress.XtraReports.UI.XRPictureBox(); this.xrLabel2 = new DevExpress.XtraReports.UI.XRLabel(); this.xrLabel1 = new DevExpress.XtraReports.UI.XRLabel(); this.TopMargin = new DevExpress.XtraReports.UI.TopMarginBand(); this.BottomMargin = new DevExpress.XtraReports.UI.BottomMarginBand(); this.northwind1 = new Northwind(); this.categoriesTableAdapter1 = new NorthwindTableAdapters.CategoriesTableAdapter(); this.DetailReport = new DevExpress.XtraReports.UI.DetailReportBand(); this.Detail1 = new DevExpress.XtraReports.UI.DetailBand(); this.xrLabel4 = new DevExpress.XtraReports.UI.XRLabel(); this.xrLabel3 = new DevExpress.XtraReports.UI.XRLabel(); this.productsTableAdapter1 = new NorthwindTableAdapters.ProductsTableAdapter(); this.CategoryId = new DevExpress.XtraReports.Parameters.Parameter(); ((System.ComponentModel.ISupportInitialize)(this.northwind1)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this)).BeginInit(); // // Detail // this.Detail.Controls.AddRange(new DevExpress.XtraReports.UI.XRControl[] { this.xrPictureBox1, this.xrLabel2, this.xrLabel1 }); this.Detail.HeightF = 91F; this.Detail.Name = "Detail"; this.Detail.Padding = new DevExpress.XtraPrinting.PaddingInfo(0, 0, 0, 0, 100F); this.Detail.TextAlignment = DevExpress.XtraPrinting.TextAlignment.TopLeft; // // xrPictureBox1 // this.xrPictureBox1.DataBindings.AddRange(new DevExpress.XtraReports.UI.XRBinding[] { new DevExpress.XtraReports.UI.XRBinding("Image", null, "Categories.Picture") }); this.xrPictureBox1.LocationFloat = new DevExpress.Utils.PointFloat(444.1667F, 10.00001F); this.xrPictureBox1.Name = "xrPictureBox1"; this.xrPictureBox1.SizeF = new System.Drawing.SizeF(195.8333F, 63.99998F); // // xrLabel2 // this.xrLabel2.DataBindings.AddRange(new DevExpress.XtraReports.UI.XRBinding[] { new DevExpress.XtraReports.UI.XRBinding("Text", null, "Categories.Description") }); this.xrLabel2.LocationFloat = new DevExpress.Utils.PointFloat(10.00001F, 50.99999F); this.xrLabel2.Name = "xrLabel2"; this.xrLabel2.Padding = new DevExpress.XtraPrinting.PaddingInfo(2, 2, 0, 0, 100F); this.xrLabel2.SizeF = new System.Drawing.SizeF(365.625F, 23F); this.xrLabel2.Text = "xrLabel2"; // // xrLabel1 // this.xrLabel1.DataBindings.AddRange(new DevExpress.XtraReports.UI.XRBinding[] { new DevExpress.XtraReports.UI.XRBinding("Text", null, "Categories.CategoryName") }); this.xrLabel1.Font = new System.Drawing.Font("Times New Roman", 9.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(204))); this.xrLabel1.ForeColor = System.Drawing.Color.Blue; this.xrLabel1.LocationFloat = new DevExpress.Utils.PointFloat(10.00001F, 10.00001F); this.xrLabel1.Name = "xrLabel1"; this.xrLabel1.Padding = new DevExpress.XtraPrinting.PaddingInfo(2, 2, 0, 0, 100F); this.xrLabel1.SizeF = new System.Drawing.SizeF(209.375F, 23F); this.xrLabel1.StylePriority.UseFont = false; this.xrLabel1.StylePriority.UseForeColor = false; this.xrLabel1.Text = "xrLabel1"; // // TopMargin // this.TopMargin.Name = "TopMargin"; this.TopMargin.Padding = new DevExpress.XtraPrinting.PaddingInfo(0, 0, 0, 0, 100F); this.TopMargin.TextAlignment = DevExpress.XtraPrinting.TextAlignment.TopLeft; // // BottomMargin // this.BottomMargin.Name = "BottomMargin"; this.BottomMargin.Padding = new DevExpress.XtraPrinting.PaddingInfo(0, 0, 0, 0, 100F); this.BottomMargin.TextAlignment = DevExpress.XtraPrinting.TextAlignment.TopLeft; // // northwind1 // this.northwind1.DataSetName = "Northwind"; this.northwind1.SchemaSerializationMode = System.Data.SchemaSerializationMode.IncludeSchema; // // categoriesTableAdapter1 // this.categoriesTableAdapter1.ClearBeforeFill = true; // // DetailReport // this.DetailReport.Bands.AddRange(new DevExpress.XtraReports.UI.Band[] { this.Detail1 }); this.DetailReport.DataAdapter = this.productsTableAdapter1; this.DetailReport.DataMember = "Categories.CategoriesProducts"; this.DetailReport.DataSource = this.northwind1; this.DetailReport.Level = 0; this.DetailReport.Name = "DetailReport"; // // Detail1 // this.Detail1.Controls.AddRange(new DevExpress.XtraReports.UI.XRControl[] { this.xrLabel4, this.xrLabel3 }); this.Detail1.HeightF = 23F; this.Detail1.Name = "Detail1"; // // xrLabel4 // this.xrLabel4.DataBindings.AddRange(new DevExpress.XtraReports.UI.XRBinding[] { new DevExpress.XtraReports.UI.XRBinding("Text", null, "Categories.CategoriesProducts.UnitPrice") }); this.xrLabel4.LocationFloat = new DevExpress.Utils.PointFloat(444.1667F, 0F); this.xrLabel4.Name = "xrLabel4"; this.xrLabel4.Padding = new DevExpress.XtraPrinting.PaddingInfo(2, 2, 0, 0, 100F); this.xrLabel4.SizeF = new System.Drawing.SizeF(100F, 23F); this.xrLabel4.Text = "xrLabel4"; // // xrLabel3 // this.xrLabel3.DataBindings.AddRange(new DevExpress.XtraReports.UI.XRBinding[] { new DevExpress.XtraReports.UI.XRBinding("Text", null, "Categories.CategoriesProducts.ProductName") }); this.xrLabel3.LocationFloat = new DevExpress.Utils.PointFloat(10.00001F, 0F); this.xrLabel3.Name = "xrLabel3"; this.xrLabel3.Padding = new DevExpress.XtraPrinting.PaddingInfo(2, 2, 0, 0, 100F); this.xrLabel3.SizeF = new System.Drawing.SizeF(279.1667F, 23F); this.xrLabel3.Text = "xrLabel3"; // // productsTableAdapter1 // this.productsTableAdapter1.ClearBeforeFill = true; // // CategoryId // this.CategoryId.Name = "CategoryId"; this.CategoryId.ParameterType = DevExpress.XtraReports.Parameters.ParameterType.Int32; this.CategoryId.Value = 1; // // XtraReport1 // this.Bands.AddRange(new DevExpress.XtraReports.UI.Band[] { this.Detail, this.TopMargin, this.BottomMargin, this.DetailReport }); this.DataAdapter = this.categoriesTableAdapter1; this.DataMember = "Categories"; this.DataSource = this.northwind1; this.FilterString = "[CategoryID] = ?CategoryId"; this.Parameters.AddRange(new DevExpress.XtraReports.Parameters.Parameter[] { this.CategoryId }); this.Version = "10.1"; ((System.ComponentModel.ISupportInitialize)(this.northwind1)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this)).EndInit(); }