网上购物系统(Task000)——经典的数据库连接
using System;
using System.Data;
using System.Data.SqlClient;
namespace WestGarden.Web
{
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";
string cmdText = "SELECT * FROM Category";
SqlConnection conn = new SqlConnection();
conn.ConnectionString = connectionString;
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;
cmd.CommandType = CommandType.Text;
cmd.CommandText = cmdText;
conn.Open();
SqlDataReader rdr = cmd.ExecuteReader();
while (rdr.Read())
{
Response.Write(rdr["Name"] + "<br/>");
}
rdr.Close();
conn.Close();
}
}
}
作者 yousuosi
补充:Web开发 , ASP.Net ,