网上购物系统(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
上一篇: 哥,这顿我请你
下一篇: 伤肝的行为有哪些 伤肝的症状