A PetShop (Task001) in Sousse -- classic database connection

Source: Internet
Author: User

Source code: 13033480 group sharing

Task 1: Classic database connection 1. Operation Step 1. Open the code file Default. aspx. cs and enter the following code in the Page_Load () function:

[Csharp]
Using System;
Using System. Data;
 
Using System. Data. SqlClient;
 
Public partial class _ Default: System. Web. UI. Page
{
Protected void Page_Load (object sender, EventArgs e)
{

String connectionString = "Server =. \ SQLEXPRESS; Database = NetShop; Trusted_Connection = SSPI ";
 
SqlConnection conn = new SqlConnection (connectionString );
 
SqlCommand cmd = new SqlCommand ();
Cmd. Connection = conn;
Cmd. CommandType = CommandType. Text;
Cmd. CommandText = "SELECT * FROM Category ";
 
Conn. Open ();

SqlDataReader rdr = cmd. ExecuteReader ();
While (rdr. Read ())
{
Response. Write (rdr ["Name"] + "</br> ");
}
 
Rdr. Close ();
Conn. Close ();
}
}
2. Right-click the Form file Default. aspx → view it in the browser. Ii. Technical Points 1. the SQL Server. NET data providers mainly include SqlConnection, SqlCommand, SqlDataReader, and SqlDataAdapter. 2. Place the cursor over the corresponding class to display its namespace and main functions.


From ASP. NET Technology

Related Article

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.