Example #1
0
    protected void Page_Load(object sender, EventArgs e)
    {
        DataSet1.CategoryDataTable Category = new DataSet1.CategoryDataTable();
        CategoryTableAdapter       catAdap  = new CategoryTableAdapter();

        DataSet1.ProductsDataTable Products = new DataSet1.ProductsDataTable();
        ProductsTableAdapter       prodAdap = new ProductsTableAdapter();

        catAdap.Fill(Category);
        prodAdap.Fill(Products);

        var result = from item in Products
                     select item;

        DataTable queriedProducts = result.CopyToDataTable <DataSet1.ProductsRow>();

        queriedProducts.TableName = "queriedProducts";
        DataSet1 ds = new DataSet1();

        ds.Tables.Add(queriedProducts);
        //DataView view = result.AsDataView<DataSet1.ProductsRow>();
        //view.RowFilter = "CategoryID = 65985";
        GridView1.DataSource = ds.Tables["queriedProducts"];
        GridView1.DataBind();
    }
    public void DataViewDemo()
    {
        DataSet1.CategoryDataTable Category = new DataSet1.CategoryDataTable();
        CategoryTableAdapter       catAdap  = new CategoryTableAdapter();

        catAdap.Fill(Category);

        DataSet1.ProductsDataTable Products = new DataSet1.ProductsDataTable();
        ProductsTableAdapter       prodAdap = new ProductsTableAdapter();

        prodAdap.Fill(Products);

        var result = from item in Products
                     select item;
        DataView view = result.AsDataView();

        view.Sort            = "ProductName desc";
        view.RowFilter       = "CategoryID = 65985";
        GridView7.DataSource = view;
        GridView7.DataBind();
        DataSet1.ProductsRow        row    = null;
        List <DataSet1.ProductsRow> myList = new List <DataSet1.ProductsRow>();

        foreach (DataRowView item in view)
        {
            row = (DataSet1.ProductsRow)item.Row;
            myList.Add(row);
        }
        GridView8.DataSource = myList;
        GridView8.DataBind();
    }
Example #3
0
        protected override void FillDataSources(XtraReport report, string reportName, bool isDesignActive)
        {
            var dataSet = (Northwind)report.GetDataSourceByName("Northwind");

            using (var adapter = new ProductsTableAdapter())
                adapter.Fill(dataSet.Products);
        }
Example #4
0
 public Window1()
 {
     InitializeComponent();
     nwindDataSet.ProductsDataTable gridData = new ProductsTableAdapter().GetData();
     FillUnboundItemsSource(gridData.Rows.Count);
     grid.ItemsSource = gridData;
 }
 //一个填充Northwind数据库中产品和供应商到DataSet中去的函数
 protected void FillDataSet()
 {
     ProductsTableAdapter productadapter = new ProductsTableAdapter();
     productadapter.Fill(ds.Products);
     SuppliersTableAdapter supplieradapter = new SuppliersTableAdapter();
     supplieradapter.Fill(ds.Suppliers);
 }
    /// <summary>
    /// GetProductData method for fetching product table data.
    /// </summary>
    public Message GetProductData()
    {
        HttpContext.Current.Session["DAP"] = "SQL";
        HttpContext.Current.Session["DBMS"] = DbEnum.DBMSType.SQLServer;

        NameValueCollection queryStrings = HttpContext.Current.Request.QueryString;

        HttpContext.Current.Session["SortExpression"] = queryStrings["sidx"];
        HttpContext.Current.Session["SortDirection"] = queryStrings["sord"];
        string currentPage = queryStrings["page"];
        string rows = queryStrings["rows"];
        int startIndex = (int.Parse(currentPage) - 1) * int.Parse(rows);
        int maximumRows = int.Parse(rows) - 1;

        ProductsTableAdapter productTableAdapter = new ProductsTableAdapter();
        DataTable productTableData = productTableAdapter.SelectMethod(startIndex, maximumRows);
        int totalCount = productTableAdapter.SelectCountMethod();

        // Calling SavejqGridJson
        DTTable dtTable = new DTTable("Product");
        object jqGridObject = dtTable.SavejqGridJson(productTableData, totalCount, currentPage, rows);

        // Converts Product table into JSon strig
        string jsonData = JsonConvert.SerializeObject(jqGridObject);

        // Converts JSON data to Message format.
        WebOperationContext.Current.OutgoingResponse.Headers.Add("X-Content-Type-Options", "nosniff");

        // returns JSON string in Message format
        return WebOperationContext.Current.CreateTextResponse(jsonData, "application/json; charset=utf-8", Encoding.UTF8);
    }
Example #7
0
        static void Main(string[] args)
        {
            using (NorthwindDataSet ds =
                new NorthwindDataSet())
            using (CategoriesTableAdapter tac =
                new CategoriesTableAdapter())
            using (ProductsTableAdapter tap =
                new ProductsTableAdapter())
            {
                tac.Fill(ds.Categories);
                tap.Fill(ds.Products);

                foreach (var item in ds.Categories)
                {
                    Console.WriteLine("{0} {1} {2}",
                        item.ItemArray);

                    NorthwindDataSet.ProductsRow[] childs =
                        item.GetProductsRows();
                    foreach (var item2 in childs)
                    {
                        Console.WriteLine("\t{0} {1} {2} {3} ",
                            item2.CategoryID,
                            item2.ProductID,
                            item2.ProductName,
                            item2.UnitPrice);
                    }
                }
            }
        }
    protected void Page_Load(object sender, EventArgs e)
    {
        ProductsTableAdapter productsAdapter = new ProductsTableAdapter();

        GridView1.DataSource = productsAdapter.GetProductsByCategoryID(1);
        GridView1.DataBind();
    }
    private void FilterProducts(string categoryName)
    {
        DrillDownDataSet     ddds = (Session["DrillDownDataSet"] as DrillDownDataSet);
        ProductsTableAdapter pta  = new ProductsTableAdapter();

        ddds.Products.Clear();
        pta.FillBy(ddds.Products, categoryName);
    }
Example #10
0
        public Northwind.ProductsDataTable GetProducts()
        {
            ProductsTableAdapter productsAdapter =
                new ProductsTableAdapter();

            return
                (productsAdapter.GetProductsBySupplierID(this.SupplierID));
        }
    //一个填充Northwind数据库中产品和供应商到DataSet中去的函数
    protected void FillDataSet()
    {
        ProductsTableAdapter productadapter = new ProductsTableAdapter();

        productadapter.Fill(ds.Products);
        SuppliersTableAdapter supplieradapter = new SuppliersTableAdapter();

        supplieradapter.Fill(ds.Suppliers);
    }
Example #12
0
        // Populate your datasources for an editing session using the following method.
        protected override void FillDataSources(XtraReport report, string reportName, bool isDesignActive)
        {
            DataSet1 dataSet = (DataSet1)report.GetDataSourceByName("XtraReport1Data");

            using (var categoriesTableAdapter = new CategoriesTableAdapter())
                using (var productsTableAdapter = new ProductsTableAdapter()) {
                    categoriesTableAdapter.Fill(dataSet.Categories);
                    productsTableAdapter.Fill(dataSet.Products);
                }
        }
        public static Northwind CreateNorthwindData()
        {
            var northwind = new Northwind();

            using (var categoriesAdapter = new CategoriesTableAdapter())
                using (var productsAdapter = new ProductsTableAdapter()) {
                    categoriesAdapter.Fill(northwind.Categories);
                    productsAdapter.Fill(northwind.Products);
                }
            return(northwind);
        }
Example #14
0
        private static object GetDataSource()
        {
            NWindDataSet dataSource = new NWindDataSet();
            var          connection = new SqlConnection();

            connection.ConnectionString = Properties.Settings.Default.NWindConnectionString;

            ProductsTableAdapter products = new ProductsTableAdapter();

            products.Connection = connection;
            products.Fill(dataSource.Products);

            return(dataSource.Products);
        }
Example #15
0
        static SalesReceipt()
        {
            ProductsTableAdapter      productsTableAdapter      = new ProductsTableAdapter();
            servicesTableAdapter      servicesTableAdapter      = new servicesTableAdapter();
            receiptModifyTableAdapter receiptModifyTableAdapter = new receiptModifyTableAdapter();
            order_lineTableAdapter    order_LineTableAdapter    = new order_lineTableAdapter();

            try
            {
                receiptModifyTableAdapter.Fill(dsSales.receiptModify);
                productsTableAdapter.Fill(dsSales.Products);
                servicesTableAdapter.Fill(dsSales.services);
                order_LineTableAdapter.Fill(dsSales.order_line);
            }
            catch (Exception) { }
        }
Example #16
0
    protected nwndDataSet GetData()
    {
        if ((nwndDataSet)Session["dataset"] == null)
        {
            nwndDataSet            ds  = new nwndDataSet();
            CategoriesTableAdapter cta = new CategoriesTableAdapter();
            ProductsTableAdapter   pta = new ProductsTableAdapter();

            cta.Fill(ds.Categories);
            pta.Fill(ds.Products);

            Session["dataset"] = ds;
        }

        return((nwndDataSet)Session["dataset"]);
    }
Example #17
0
        static void Main(string[] args)
        {
            SqlConnection conn = new SqlConnection(@"Data Source=(LocalDB)\SQLLocalDb;Initial Catalog=SportsStore;Integrated Security=True;Connect Timeout=15;Encrypt=False;TrustServerCertificate=False");

            //SP_Demo(conn);
            //await ReaderAccess(conn);
            DsProducts           ds      = new DsProducts();
            ProductsTableAdapter adapter = new ProductsTableAdapter();

            adapter.Connection = conn;
            conn.Open();
            adapter.Fill(ds.Products);
            ds.Products.AddProductsRow("Pen", "Pen with A Man", "Stationery", 12.50M);
            ds.WriteXml(@"C:\Lab\Products2.xml", System.Data.XmlWriteMode.DiffGram);
            adapter.Update(ds.Products);
            conn.Close();
            conn.Dispose();
        }
Example #18
0
        static object CreateDataSource()
        {
            var dataSource = new nwindDataSet();
            var connection = new OleDbConnection();

            connection.ConnectionString = Properties.Settings.Default.nwindConnectionString;

            CategoriesTableAdapter categories = new CategoriesTableAdapter();

            categories.Connection = connection;
            categories.Fill(dataSource.Categories);

            ProductsTableAdapter products = new ProductsTableAdapter();

            products.Connection = connection;
            products.Fill(dataSource.Products);

            return(dataSource);
        }
Example #19
0
        private BindingSource GetDataSource()
        {
            nwindDataSet    dataSource = new nwindDataSet();
            OleDbConnection connection = new OleDbConnection();

            connection.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\nwind.mdb";

            ProductsTableAdapter products = new ProductsTableAdapter();

            products.Connection = connection;
            products.Fill(dataSource.Products);

            BindingSource bindingSource = new BindingSource();

            bindingSource.DataSource = dataSource;
            bindingSource.DataMember = "Products";

            return(bindingSource);
        }
    public void StronglyTypedDataSet()
    {
        DataSet1.CategoryDataTable CategoryDT        = new DataSet1.CategoryDataTable();
        CategoryTableAdapter       CategoryTBAdapter = new CategoryTableAdapter();

        DataSet1.ProductsDataTable ProductsDT        = new DataSet1.ProductsDataTable();
        ProductsTableAdapter       ProductsTBAdapter = new ProductsTableAdapter();

        CategoryTBAdapter.Fill(CategoryDT);
        ProductsTBAdapter.Fill(ProductsDT);

        var result = from cat in CategoryDT
                     join prod in ProductsDT
                     on cat.CategoryID equals prod.CategoryID
                     where cat.CategoryID == 65985
                     select new { CategoryName = cat.CategoryName, ProductName = prod.ProductName, UnitPrice = prod.UnitPrice };

        GridView6.DataSource = result;
        GridView6.DataBind();
    }
Example #21
0
        private static void Main()
        {
            var dataSet    = new NorthwindDataSet();
            var tblAdapter = new ProductsTableAdapter();

            tblAdapter.Fill(dataSet.Products);

            var tblAdapterCategories = new CategoriesTableAdapter();

            tblAdapterCategories.Fill(dataSet.Categories);

            foreach (var row in dataSet.Products)
            {
                Console.WriteLine($"{row.ProductName}");
            }
            var peterProduct   = dataSet.Products.FirstOrDefault(x => x.ProductName == "Peter");
            var gabrielProduct = dataSet.Products.FirstOrDefault(x => x.ProductName == "Gabriel");

            if (gabrielProduct == default(NorthwindDataSet.ProductsRow) && peterProduct == default(NorthwindDataSet.ProductsRow))
            {
                var newRow = dataSet.Products.NewProductsRow();
                newRow.ProductName   = "Gabriel";
                newRow.Discontinued  = false;
                newRow.CategoriesRow = dataSet.Categories.First();
                dataSet.Products.AddProductsRow(newRow);
            }
            else if (peterProduct == default(NorthwindDataSet.ProductsRow))
            {
                gabrielProduct.BeginEdit();
                gabrielProduct.ProductName = "Peter";
                gabrielProduct.EndEdit();
            }
            else if (gabrielProduct == default(NorthwindDataSet.ProductsRow))
            {
                peterProduct.Delete();
            }
            tblAdapter.Update(dataSet);
            Console.ReadLine();
        }
    protected void Page_Load(object sender, EventArgs e)
    {
        DataSet1.CategoryDataTable Category = new DataSet1.CategoryDataTable();
        CategoryTableAdapter catAdap = new CategoryTableAdapter();

        DataSet1.ProductsDataTable Products = new DataSet1.ProductsDataTable();
        ProductsTableAdapter prodAdap = new ProductsTableAdapter();

        catAdap.Fill(Category);
        prodAdap.Fill(Products);

        var result = from item in Products
                     select item;

        DataTable queriedProducts = result.CopyToDataTable<DataSet1.ProductsRow>();
        queriedProducts.TableName = "queriedProducts";
        DataSet1 ds = new DataSet1();
        ds.Tables.Add(queriedProducts);
        //DataView view = result.AsDataView<DataSet1.ProductsRow>();
        //view.RowFilter = "CategoryID = 65985";
        GridView1.DataSource = ds.Tables["queriedProducts"];
        GridView1.DataBind();
    }
    public void StronglyTypedDataSet()
    {
        DataSet1.CategoryDataTable CategoryDT = new DataSet1.CategoryDataTable();
        CategoryTableAdapter CategoryTBAdapter = new CategoryTableAdapter();

        DataSet1.ProductsDataTable ProductsDT = new DataSet1.ProductsDataTable();        
        ProductsTableAdapter ProductsTBAdapter = new ProductsTableAdapter();

        CategoryTBAdapter.Fill(CategoryDT);
        ProductsTBAdapter.Fill(ProductsDT);

        var result = from cat in CategoryDT
                     join prod in ProductsDT
                     on cat.CategoryID equals prod.CategoryID
                     where cat.CategoryID == 65985
                     select new { CategoryName = cat.CategoryName, ProductName = prod.ProductName, UnitPrice = prod.UnitPrice };        

        GridView6.DataSource = result;
        GridView6.DataBind();
    }
Example #24
0
        private void printDocument1_BeginPrint(object sender, System.Drawing.Printing.PrintEventArgs e)
        {
            sayfaNo = 1;
            printLabel.Text = string.Empty;
            printLabel.Visible = true;
            printProgress.Value = int.Parse(sayfaNo.ToString());
            printProgress.Maximum = int.Parse(toplamSayfa.ToString());
            printProgress.Minimum = printProgress.Value;
            printProgress.Visible = true;

            //Veriler = new List<ProductClass>();

            using (ProductsTableAdapter ta =
                new ProductsTableAdapter())
            {
                var dt = ta.GetData();

                //Veriler = dt.Select(x => new ProductClass()
                //{
                //    ProductID = x.ProductID.ToString(),
                //    ProductName = x.ProductName,
                //    UnitPrice = x.UnitPrice.ToString(),
                //    UnitsInStock = x.UnitsInStock.ToString(),
                //    TotalPrice = x.TotalPrice.ToString()
                //}).ToList();

                Bitmap bm = new Bitmap(100, 100);
                Graphics g = Graphics.FromImage(bm);

                Veriler = (from x in dt
                           select new ProductClass()
                             {
                                 ProductID = x.ProductID.ToString(),
                                 ProductIDWidth = g.MeasureString(x.ProductID.ToString(), f).Width + 5,
                                 ProductName = x.ProductName,
                                 ProductNameWidth = g.MeasureString(x.ProductName, f).Width + 5,
                                 UnitPrice = x.UnitPrice.ToString("N2"),
                                 UnitPriceWidth = g.MeasureString(x.UnitPrice.ToString("N2"), f).Width + 5,
                                 UnitsInStock = x.UnitsInStock.ToString(),
                                 UnitsInStockWidth = g.MeasureString(x.UnitsInStock.ToString(), f).Width + 5,
                                 TotalPrice = x.TotalPrice.ToString("N2"),
                                 TotalPriceWidth = g.MeasureString(x.TotalPrice.ToString("N2"), f).Width + 5,
                             }).ToList();

                KolonGenislikleri.Clear();
                KolonGenislikleri.Add("ProductID",
                    g.MeasureString("Product ID ", f).Width + 5);

                KolonGenislikleri.Add("ProductName",
                    g.MeasureString("Product Name ", f).Width + 5);

                KolonGenislikleri.Add("UnitPrice",
                    g.MeasureString("Unit Price ", f).Width + 5);

                KolonGenislikleri.Add("UnitsInStock",
                    g.MeasureString("Units In Stock ", f).Width + 5);

                KolonGenislikleri.Add("TotalPrice",
                    g.MeasureString("Total Price ", f).Width + 5);

                float ff = Veriler.Max(x => x.ProductIDWidth);
                if (KolonGenislikleri["ProductID"] < ff)
                    KolonGenislikleri["ProductID"] = ff;

                ff = Veriler.Max(x => x.ProductNameWidth);
                if (KolonGenislikleri["ProductName"] < ff)
                    KolonGenislikleri["ProductName"] = ff;

                ff = Veriler.Max(x => x.UnitPriceWidth);
                if (KolonGenislikleri["UnitPrice"] < ff)
                    KolonGenislikleri["UnitPrice"] = ff;

                ff = Veriler.Max(x => x.UnitsInStockWidth);
                if (KolonGenislikleri["UnitsInStock"] < ff)
                    KolonGenislikleri["UnitsInStock"] = ff;

                ff = Veriler.Max(x => x.TotalPriceWidth);
                if (KolonGenislikleri["TotalPrice"] < ff)
                    KolonGenislikleri["TotalPrice"] = ff;

                satirYuksekligi =
                    g.MeasureString("ĞÖİ纪Çygğ", f).Height;
            }
        }
Example #25
0
        public void CopyProducts()
        {
            List<Product> products = new List<Product>();
            Hashtable suppliers = new Hashtable();
            Hashtable categories = new Hashtable();
            //Processing Products
            LogMessage("Reading Products...", false);
            ProductsTableAdapter adapter1 = new ProductsTableAdapter();
            NorthwindDb4o.NorthwindDataSet.ProductsDataTable table1 = adapter1.GetData();
            LogMessage("processing " + table1.Count.ToString() + " rows", true);
            foreach (NorthwindDb4o.NorthwindDataSet.ProductsRow row in table1)
            {
                Product p = new Product();

                p.ProductID = row.ProductID;
                p.ProductName = row.ProductName;
                if (!row.IsSupplierIDNull())
                    suppliers.Add(p.ProductID, row.SupplierID);
                if (!row.IsCategoryIDNull())
                    categories.Add(p.ProductID, row.CategoryID);
                p.QuantityPerUnit = row.IsQuantityPerUnitNull() ? null : row.QuantityPerUnit;
                p.UnitPrice = row.IsUnitPriceNull() ? 0 : Convert.ToDouble(row.UnitPrice);
                p.UnitsInStock = row.IsUnitsInStockNull() ? 0 : row.UnitsInStock;
                p.UnitsOnOrder = row.IsUnitsOnOrderNull() ? 0 : row.UnitsOnOrder;
                p.ReorderLevel = row.IsReorderLevelNull() ? 0 : row.ReorderLevel;
                p.Discontinued = row.Discontinued;

                products.Add(p);
            }
            foreach (Product p in products)
            {
                LogMessage("Product: " + p.ProductID.ToString() + " ...", false);
                if (suppliers.ContainsKey(p.ProductID))
                {
                    LogMessage("linking member...", false);
                    long supplierID = Convert.ToInt64(suppliers[p.ProductID]);
                    Supplier found = (Supplier)Db4oUtil.GetByNumericalID(container, typeof(Supplier), "supplierID", supplierID);
                    p.SupplierID = found;
                }
                if (categories.ContainsKey(p.ProductID))
                {
                    LogMessage("linking member...", false);
                    long categoryID = Convert.ToInt64(categories[p.ProductID]);
                    Category found = (Category)Db4oUtil.GetByNumericalID(container, typeof(Category), "categoryID", categoryID);
                    p.CategoryID = found;
                }
                container.Store(p);
                LogMessage("saved (" + p.ProductID.ToString() + ")", true);
            }
            container.Commit();
            long objectCount = Db4oUtil.GetAllInstances(container, typeof(Product)).Count;
            if (table1.Count == objectCount)
                LogMessage(table1.Count + " objects saved", true);
            else
                LogMessage("Error: " + table1.Count + " rows retrieved but " + objectCount + " objects were saved", true);
            LogMessage("Done with Products" + Environment.NewLine, true);
        }
        public void ProcessRequest(HttpContext context)
        {
            _context = context;
            _req = context.Request;
            _res = context.Response;

            if (!string.IsNullOrEmpty(_req.QueryString["t"]))
            {
                switch (_req.QueryString["t"].ToLower())
                {
                    case "categories":
                        if (!string.IsNullOrEmpty(_req.QueryString["id"]))
                        {
                            cata = new CategoriesTableAdapter();
                            var ds = new NorthwindDataSet();
                            cata.FillByCategoryID(ds.Categories, int.Parse(_req.QueryString["id"]));
                            foreach (var item in ds.Categories)
                            {
                                item.Picture = null;
                            }
                            _res.ContentType = "text/xml";
                            _res.ContentEncoding = Encoding.UTF8;
                            _res.Write("<?xml version=\"1.0\" encoding=\"utf-8\" ?>");
                            ds.WriteXml(_res.OutputStream);

                        }
                        else
                        {
                            cata = new CategoriesTableAdapter();
                            var ds = new NorthwindDataSet();
                            cata.Fill(ds.Categories);
                            foreach (var item in ds.Categories)
                            {
                                item.Picture = null;
                            }
                            _res.ContentType = "text/xml";
                            _res.ContentEncoding = Encoding.UTF8;
                            _res.Write("<?xml version=\"1.0\" encoding=\"utf-8\" ?>");
                            ds.WriteXml(_res.OutputStream);

                        }
                        return;

                    case "products":
                        if (!string.IsNullOrEmpty(_req.QueryString["id"]))
                        {
                            prta = new ProductsTableAdapter();
                            var ds = new NorthwindDataSet();
                            prta.FillByProductID(ds.Products, int.Parse(_req.QueryString["id"]));
                            _res.ContentType = "text/xml";
                            _res.ContentEncoding = Encoding.UTF8;
                            _res.Write("<?xml version=\"1.0\" encoding=\"utf-8\" ?>");
                            ds.WriteXml(_res.OutputStream);

                        }
                        else if (!string.IsNullOrEmpty(_req.QueryString["cid"]))
                        {
                            prta = new ProductsTableAdapter();
                            var ds = new NorthwindDataSet();
                            prta.FillByCategoryID(ds.Products, int.Parse(_req.QueryString["cid"]));
                            _res.ContentType = "text/xml";
                            _res.ContentEncoding = Encoding.UTF8;
                            _res.Write("<?xml version=\"1.0\" encoding=\"utf-8\" ?>");
                            ds.WriteXml(_res.OutputStream);

                        }
                        else
                        {
                            prta = new ProductsTableAdapter();
                            var ds = new NorthwindDataSet();
                            prta.Fill(ds.Products);
                            _res.ContentType = "text/xml";
                            _res.ContentEncoding = Encoding.UTF8;
                            _res.Write("<?xml version=\"1.0\" encoding=\"utf-8\" ?>");
                            ds.WriteXml(_res.OutputStream);

                        }
                        return;
                    default:
                        break;
                }
            }
        }
Example #27
0
        private void CopyProducts(IOdb odb)
        {
            var products = new List<Product>();
            var suppliers = new Hashtable();
            var categories = new Hashtable();
            //Processing Products
            LogMessage("Reading Products...", false);
            var adapter1 = new ProductsTableAdapter();
            var table1 = adapter1.GetData();
            LogMessage("processing " + table1.Count.ToString() + " rows", true);
            foreach (var row in table1)
            {
                var p = new Product
                            {
                                ProductID = row.ProductID,
                                ProductName = row.ProductName,
                                QuantityPerUnit = row.IsQuantityPerUnitNull() ? null : row.QuantityPerUnit,
                                UnitPrice = row.IsUnitPriceNull() ? 0 : Convert.ToDouble(row.UnitPrice),
                                UnitsInStock = row.IsUnitsInStockNull() ? 0 : row.UnitsInStock,
                                UnitsOnOrder = row.IsUnitsOnOrderNull() ? 0 : row.UnitsOnOrder,
                                ReorderLevel = row.IsReorderLevelNull() ? 0 : row.ReorderLevel,
                                Discontinued = row.Discontinued
                            };

                if (!row.IsSupplierIDNull())
                    suppliers.Add(p.ProductID, row.SupplierID);
                if (!row.IsCategoryIDNull())
                    categories.Add(p.ProductID, row.CategoryID);

                products.Add(p);
            }
            foreach (var p in products)
            {
                LogMessage("Product: " + p.ProductID.ToString() + " ...", false);
                if (suppliers.ContainsKey(p.ProductID))
                {
                    LogMessage("linking member...", false);
                    var supplierID = Convert.ToInt64(suppliers[p.ProductID]);
                    var found = NDbUtil.GetByNumericalID<Supplier>(odb, Supplier.PK, supplierID);
                    p.Supplier = found;
                }
                if (categories.ContainsKey(p.ProductID))
                {
                    LogMessage("linking member...", false);
                    var categoryID = Convert.ToInt64(categories[p.ProductID]);
                    var found = NDbUtil.GetByNumericalID<Category>(odb, Category.PK, categoryID);
                    p.Category = found;
                }
                odb.Store(p);

                LogMessage("saved (" + p.ProductID.ToString() + ")", true);
            }
            odb.Commit();

            LogMessage("Commit done, starting create index ...", false);
            odb.IndexManagerFor<Product>().AddUniqueIndexOn("Product_ProductID_PK_index", Product.PK);
            odb.Commit();
            LogMessage(" index created.", true);

            long objectCount = NDbUtil.GetAllInstances<Product>(odb).Count;
            if (table1.Count == objectCount)
                LogMessage(table1.Count + " objects saved", true);
            else
                LogMessage("Error: " + table1.Count + " rows retrieved but " + objectCount + " objects were saved", true);
            LogMessage("Done with Products" + Environment.NewLine, true);
        }
    public void DataViewDemo()
    {
        DataSet1.CategoryDataTable Category = new DataSet1.CategoryDataTable();
        CategoryTableAdapter catAdap = new CategoryTableAdapter();
        catAdap.Fill(Category);

        DataSet1.ProductsDataTable Products = new DataSet1.ProductsDataTable();
        ProductsTableAdapter prodAdap = new ProductsTableAdapter();
        prodAdap.Fill(Products);

        var result = from item in Products
                     select item;
        DataView view = result.AsDataView();
        view.Sort = "ProductName desc";
        view.RowFilter = "CategoryID = 65985";        
        GridView7.DataSource = view;
        GridView7.DataBind();
        DataSet1.ProductsRow row = null;
        List<DataSet1.ProductsRow> myList = new List<DataSet1.ProductsRow>();
        foreach (DataRowView item in view)
        {
            row = (DataSet1.ProductsRow)item.Row;
            myList.Add(row);
        }
        GridView8.DataSource = myList;
        GridView8.DataBind();
    }
        private void CopyProducts(IOdb odb)
        {
            var products   = new List <Product>();
            var suppliers  = new Hashtable();
            var categories = new Hashtable();

            //Processing Products
            LogMessage("Reading Products...", false);
            var adapter1 = new ProductsTableAdapter();
            var table1   = adapter1.GetData();

            LogMessage("processing " + table1.Count.ToString() + " rows", true);
            foreach (var row in table1)
            {
                var p = new Product
                {
                    ProductID       = row.ProductID,
                    ProductName     = row.ProductName,
                    QuantityPerUnit = row.IsQuantityPerUnitNull() ? null : row.QuantityPerUnit,
                    UnitPrice       = row.IsUnitPriceNull() ? 0 : Convert.ToDouble(row.UnitPrice),
                    UnitsInStock    = row.IsUnitsInStockNull() ? 0 : row.UnitsInStock,
                    UnitsOnOrder    = row.IsUnitsOnOrderNull() ? 0 : row.UnitsOnOrder,
                    ReorderLevel    = row.IsReorderLevelNull() ? 0 : row.ReorderLevel,
                    Discontinued    = row.Discontinued
                };

                if (!row.IsSupplierIDNull())
                {
                    suppliers.Add(p.ProductID, row.SupplierID);
                }
                if (!row.IsCategoryIDNull())
                {
                    categories.Add(p.ProductID, row.CategoryID);
                }

                products.Add(p);
            }
            foreach (var p in products)
            {
                LogMessage("Product: " + p.ProductID.ToString() + " ...", false);
                if (suppliers.ContainsKey(p.ProductID))
                {
                    LogMessage("linking member...", false);
                    var supplierID = Convert.ToInt64(suppliers[p.ProductID]);
                    var found      = NDbUtil.GetByNumericalID <Supplier>(odb, Supplier.PK, supplierID);
                    p.Supplier = found;
                }
                if (categories.ContainsKey(p.ProductID))
                {
                    LogMessage("linking member...", false);
                    var categoryID = Convert.ToInt64(categories[p.ProductID]);
                    var found      = NDbUtil.GetByNumericalID <Category>(odb, Category.PK, categoryID);
                    p.Category = found;
                }
                odb.Store(p);

                LogMessage("saved (" + p.ProductID.ToString() + ")", true);
            }
            odb.Commit();

            LogMessage("Commit done, starting create index ...", false);
            odb.IndexManagerFor <Product>().AddUniqueIndexOn("Product_ProductID_PK_index", Product.PK);
            odb.Commit();
            LogMessage(" index created.", true);

            long objectCount = NDbUtil.GetAllInstances <Product>(odb).Count;

            if (table1.Count == objectCount)
            {
                LogMessage(table1.Count + " objects saved", true);
            }
            else
            {
                LogMessage("Error: " + table1.Count + " rows retrieved but " + objectCount + " objects were saved", true);
            }
            LogMessage("Done with Products" + Environment.NewLine, true);
        }