数据源和数据控件的关系是什么?在ASP.NET中,如何实现数据库中数据显示的功能?

2024-12-29 01:50:27
推荐回答(1个)
回答1:

很简单的连接数据库
数据访问层
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();
}