Online Shopping System (Task001)-Public dataset Model

Source: Internet
Author: User

1. Place the connection string in the Web. config file.

[Html] <connectionStrings>
<Add name = "NetShopConnString" connectionString = "server =. \ SQLEXPRESS; database = NetShop; integrated security = SSPI;" providerName = "System. Data. SqlClient"/>
</ConnectionStrings>
<ConnectionStrings>
<Add name = "NetShopConnString" connectionString = "server =. \ SQLEXPRESS; database = NetShop; integrated security = SSPI;" providerName = "System. Data. SqlClient"/>
</ConnectionStrings>

2. Add a class library Model.

3. Add the CategoryInfo. cs class to the Model. The Code is as follows:

[Csharp] using System;
Using System. Collections. Generic;
Using System. Text;
 
Namespace WestGarden. Model
{
Public class CategoryInfo
{
Private string categoryid;
Private string name;
Private string descn;
 
Public CategoryInfo (){}
 
Public CategoryInfo (string categoryid, string name, string descn)
{
This. categoryid = categoryid;
This. name = name;
This. descn = descn;
}
 
Public string CategoryId
{
Get {return categoryid ;}
}
Public string Name
{
Get {return name ;}
}
Public string Descn
{
Get {return descn ;}
}
}
}
Using System;
Using System. Collections. Generic;
Using System. Text;

Namespace WestGarden. Model
{
Public class CategoryInfo
{
Private string categoryid;
Private string name;
Private string descn;

Public CategoryInfo (){}

Public CategoryInfo (string categoryid, string name, string descn)
{
This. categoryid = categoryid;
This. name = name;
This. descn = descn;
}

Public string CategoryId
{
Get {return categoryid ;}
}
Public string Name
{
Get {return name ;}
}
Public string Descn
{
Get {return descn ;}
}
}
}
 

4. Add reference → project → Model, Defualt, and aspx. cs to using WestGarden. Model. The Code is as follows:

[Csharp] using System;
Using System. Data;
Using System. Data. SqlClient;
Using System. Configuration;
Using System. Collections. Generic;
Using WestGarden. Model;
 
Namespace WestGarden. Web
{
Public partial class Default: System. Web. UI. Page
{
Protected void Page_Load (object sender, EventArgs e)
{
IList <CategoryInfo> catogories = new List <CategoryInfo> ();
 
String connectionString = ConfigurationManager. ConnectionStrings ["NetShopConnString"]. ConnectionString;
String plain text = "SELECT * FROM Category ";
 
SqlConnection conn = new SqlConnection (connectionString );
 
SqlCommand cmd = new SqlCommand ();
Cmd. Connection = conn;
Cmd. CommandType = CommandType. Text;
Cmd. CommandText = plain text;
 
Conn. Open ();
 
SqlDataReader rdr = cmd. ExecuteReader ();
While (rdr. Read ())
{
CategoryInfo category = new CategoryInfo (rdr. GetString (0), rdr. GetString (1), rdr. GetString (2 ));
Catogories. Add (category );
}
 
Rdr. Close ();
Conn. Close ();
 
DdlCategories. DataSource = catogories;
DdlCategories. DataTextField = "Name ";
DdlCategories. DataValueField = "CategoryId ";
DdlCategories. DataBind ();
}
}
}

 


Author: yousuosi

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.