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