很简单的连接数据库
数据访问层
public DataView gerDataView()
{
SqlConnection conn = new SqlConnection(ConfigurationSettings.AppSettings["Connection"]);
SqlDataAdapter sda = new SqlDataAdapter("select * from Chinese",conn);
DataSet ds = new DataSet();
sda.Fill(ds);
DataView dv = new DataView(ds.Tables[0]);
return dv;
}
用户使用层
private void Button1_Click(object sender, System.EventArgs e)
{
Session["name"] = TextBox1.Text.ToString();
Response.Redirect("_SearchResult.aspx");
}
显示层
private void Page_Load(object sender, System.EventArgs e)
{
_conn c = new _conn();
DataGrid1.DataSource = c.Search(Session["name"].ToString());
DataGrid1.DataBind();
}