Aspose.Cells.GridWeb.Examples.CSharp.RowsAndColumns.CreateSubtotal.LoadData C# (CSharp) Метод

LoadData() приватный Метод

private LoadData ( string sort ) : void
sort string
Результат void
        private void LoadData(string sort)
        {
            // Loads data from access database.
            DataSet ds = new DataSet();

            // Create path to database file
            string path = (this.Master as Site).GetDataDir();

            // Create database connection object
            OleDbConnection conn = new OleDbConnection();

            // Create connection string to database
            conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + path + "\\RowsAndColumns\\Database\\Northwind.mdb";

            // Write select command
            string sql = "SELECT Products.ProductID, Categories.CategoryName, Suppliers.CompanyName, Products.ProductName, Products.QuantityPerUnit, Products.UnitPrice FROM Suppliers INNER JOIN (Categories INNER JOIN Products ON Categories.CategoryID = Products.CategoryID) ON Suppliers.SupplierID = Products.SupplierID";

            // Create data adapter object
            OleDbDataAdapter da = new OleDbDataAdapter(sql, conn);
            try
            {
                // Connects to database and fetches data.
                da.Fill(ds, "Products");
                // Sorting
                DataView productsView = new DataView(ds.Tables["Products"], "", sort, DataViewRowState.CurrentRows);

                // Clear gridweb worksheet
                GridWeb1.WebWorksheets.Clear();

                // Import data from dataview
                GridWeb1.WebWorksheets.ImportDataView(productsView, null, null);

                // Sets column width.
                GridWeb1.WebWorksheets[0].Cells.SetColumnWidth(0, new Unit(108.75, UnitType.Point));
                GridWeb1.WebWorksheets[0].Cells.SetColumnWidth(1, new Unit(74.25, UnitType.Point));
                GridWeb1.WebWorksheets[0].Cells.SetColumnWidth(2, new Unit(181.5, UnitType.Point));
                GridWeb1.WebWorksheets[0].Cells.SetColumnWidth(3, new Unit(155.25, UnitType.Point));
                GridWeb1.WebWorksheets[0].Cells.SetColumnWidth(4, new Unit(96, UnitType.Point));
                GridWeb1.WebWorksheets[0].Cells.SetColumnWidth(5, new Unit(47.25, UnitType.Point));
            }
            finally
            {
                // Close database connection
                conn.Close();
            }
        }