
数据源和数据控件的关系是什么?在ASP.NET中,如何实现数据库中数据显示的功能? 10
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();
}
数据访问层
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();
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询