ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • 아래에 있는 ShoppingCart 소스 추가!! ProductInfo 소스 파일
    예전 글들/.NET, C# 2010. 12. 27. 14:00
    반응형

    흠....뭔가 한페이지 완성한 기분..좋긴 좋은데 쩝....원래 소스 그냥 복사한 기분이네
    언제쯤 마음대로 코딩 할 때가 오려나
    소스 분석해야겠군
    프로젝트 폴더 아래 ProductInfo소스 파일 추가해서 아래 소스 복사하면 문제 없이 돌아갑니다~

    소스
    - ProdductInfo.aspx 소스
    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ProductInfo.aspx.cs" Inherits="WebApplication11.ProductInfo" %>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
    </head>
    <body>
        <table><tr>
            <td>
                <asp:Label runat="server" ID="msg" Font-Names="verdana" Font-Size="8pt" />
            </td>
        </tr></table>
    </body>
    </html>

    - ProductInfo.aspx.cs 소스
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Data.SqlClient;
    using System.Data;
    using System.Text;

    namespace WebApplication11
    {
        public partial class ProductInfo : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
                int ProductID = Convert.ToInt32(Request["id"]);
                if (ProductID < 1)
                {
                    Response.Write("No Valid ID Specified");
                    Response.End();
                }
                else
                    GetMoreInfo(ProductID);
            }

            private void GetMoreInfo(int ProductID)
            {
                String strConn = @"Data Source=.\SQLEXPRESS;AttachDbFilename=" + "C:\\Program Files\\Microsoft SQL Server\\MSSQL.1\\MSSQL\\Data\\northwind_Data.mdf" + ";Integrated Security=True;Connect Timeout=30;User Instance=True";
                SqlConnection conn = new SqlConnection(strConn);
                String strCmd = "SELECT UnitsOnOrder, ProductName, c.CategoryName, C.Description, " +
                                    "s.CompanyName, s.Address, s.City FROM Products AS p " +
                                    "INNER JOIN Categories AS c ON p.CategoryID = c.CategoryID " +
                                    "INNER JOIN Suppliers AS s ON p.SupplierID = s.SupplierID " +
                                    "WHERE ProductID = @ProductID";
                SqlCommand cmd = new SqlCommand(strCmd, conn);
                cmd.Parameters.Add("@ProductID", SqlDbType.Int).Value = ProductID;

                conn.Open();
                SqlDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
                dr.Read();
                DisplayInfo(ProductID, dr);
                dr.Close();
            }

            private void DisplayInfo(int ProductID, SqlDataReader reader)
            {
                StringBuilder sb = new StringBuilder("");
                sb.Append(String.Format("<b>{0}-{1}</b>, {2}<br>", ProductID, reader["ProductName"], reader["CategoryName"]));
                sb.Append(reader["Description"].ToString());
                sb.Append("<hr><b>");
                sb.Append(reader["Description"].ToString());
                sb.Append("</b> units currently on order.<hr>");
                sb.Append(reader["Address"].ToString());
                sb.Append("<br><i>");
                sb.Append(reader["Address"].ToString());
                sb.Append("<br>");
                sb.Append(reader["City"].ToString());
                sb.Append("</i>");
                msg.Text = sb.ToString();
            }
        }
    }

    반응형

    댓글

Designed by Tistory.