Пример #1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            Response.Write(
                "Write a program that retrieves the images for all categories in the Northwind database and stores them as JPG files in the file system.<br>");

            RepairYourDatabase();

            string query = "SELECT Picture FROM [dbo].[Categories]";

            SqlProvider.ExecuteSqlQueryReturnValue(query, null, delegate(SqlDataReader reader)
            {
                List <string> images = new List <string>();
                while (reader.Read())
                {
                    var folder = Server.MapPath("\\Images\\Categories\\");
                    if (Helpers.DirectoryExist(folder))
                    {
                        var filePath = folder + images.Count + ".Jpeg";
                        byte[] data  = (byte[])reader["Picture"];
                        WriteBinaryFile(filePath, data);
                        images.Add(filePath);
                    }
                }

                grdResult.DataSource = images;
                grdResult.DataBind();
            });
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            Response.Write("Write a program that retrieves from the Northwind sample database in MS SQL Server the number of  rows in the Categories table.<br>");

            string query = "SELECT COUNT(*) from [dbo].[Categories]";

            SqlProvider.ExecuteSqlQueryReturnValue(query, null, delegate(SqlDataReader reader)
            {
                grdResult.DataSource = reader;
                grdResult.DataBind();
            });
        }
        protected void btnSearch_Click(object sender, EventArgs e)
        {
            string query = "SELECT ProductName FROM Products WHERE CHARINDEX (@SearchOption, ProductName)>0";

            Dictionary <string, object> parametters = new Dictionary <string, object>();

            parametters.Add("SearchOption", txtSearchOption.Text);

            SqlProvider.ExecuteSqlQueryReturnValue(query, parametters, delegate(SqlDataReader reader)
            {
                grdResult.DataSource = reader;
                grdResult.DataBind();
            });
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            Response.Write(
                "Write a program that retrieves from the Northwind database all product categories and the names of the products in each category. Can you do this with a single SQL query (with table join)?<br>");

            string query =
                "SELECT c.CategoryName, p.ProductName From Categories c JOIN Products p ON c.CategoryID = p.CategoryID";

            SqlProvider.ExecuteSqlQueryReturnValue(query, null, delegate(SqlDataReader reader)
            {
                grdResult.DataSource = reader;
                grdResult.DataBind();
            });
        }