private DataTable GetCategoriesDataTable()
        {
            string connString = new NorthwindContext().Database.Connection.ConnectionString;
            string selectCategoriesStmt = "Select CategoryID as ID, CategoryName, Description from Categories";

            SqlDataAdapter da = new SqlDataAdapter(selectCategoriesStmt, connString);
            DataTable dtData = new DataTable("Categories");
            da.Fill(dtData);

            dtData.PrimaryKey = new DataColumn[] { dtData.Columns["ID"] };
            return dtData;
        }
        private DataTable GetProductsDataTable()
        {
            string connString = new NorthwindContext().Database.Connection.ConnectionString;
            string selectProductsStmt = "Select ProductID as ID, ProductName, CategoryID, UnitPrice, UnitsInStock, Discontinued  from Products";

            SqlDataAdapter da = new SqlDataAdapter(selectProductsStmt, connString);
            DataTable dtData = new DataTable("Products");
            da.Fill(dtData);

            dtData.PrimaryKey = new DataColumn[] { dtData.Columns["ID"] };
            return dtData;
        }
Пример #3
0
 private DataTable GetCustomerDataTable()
 {
     NorthwindContext ctx =new NorthwindContext();
     SqlConnection conn = (SqlConnection)ctx.Database.Connection;
     DataTable dt = new DataTable();
     using (SqlConnection con = conn)
     {
         using (SqlDataAdapter adapter = new SqlDataAdapter("SELECT * FROM CUSTOMERS", con))
         {
             adapter.Fill(dt);
         }
     }
     return dt;
 }