Ejemplo n.º 1
0
    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();
    }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            DataSet1.categoriesDataTable dtc = new DataSet1.categoriesDataTable();
            DataSet1.categoriesRow       dr  = dtc.NewcategoriesRow();
            DataSet1.categoriesRow       dr1 = dtc.NewcategoriesRow();
            dr["Name"]  = "IT";
            dr1["Name"] = "OOP";
            dtc.Rows.Add(dr);
            dtc.Rows.Add(dr1);

            foreach (DataRow item in dtc.Rows)
            {
                Console.WriteLine("categoryId: {0}, category Name: '{1}'", item["Id"], item["Name"]);
            }

            for (int i = 0; i < dtc.Rows.Count; i++)
            {
                Console.WriteLine("categoryId: {0}, category Name: '{1}'", dtc.Rows[i]["Id"], dtc.Rows[i]["Name"]);
            }

            Console.WriteLine();

            DataSet1.ProductsDataTable p1 = new DataSet1.ProductsDataTable();

            for (int i = 0; i < 10; i++)
            {
                DataSet1.ProductsRow pr = p1.NewProductsRow();
                pr["Id"]   = i + 1;
                pr["Name"] = "Product " + (i + 1);
                p1.Rows.Add(pr);
            }

            foreach (DataRow item in p1.Rows)
            {
                Console.WriteLine("product Id: {0} , product Name: '{1}'", item["Id"], item["Name"]);
            }



            Console.ReadKey();
        }