protected void Page_Load(object sender, EventArgs e)
{
DataSet dsSource = new DataSet(); //創建源數據集
DataSet dsTarget = new DataSet(); //創建目標數據集
string conStr = ConfigurationManager.ConnectionStrings["conStr"].ToString();
using (SqlConnection con = new SqlConnection(conStr))//創建數據連接
{
//創建數據適配器
SqlDataAdapter sda = new SqlDataAdapter("select * from DictionaryType", con);
sda.Fill(dsSource, "DictionaryType");//將字典類添加到源數據集
sda = new SqlDataAdapter("select * from DictionaryItem", con);
sda.Fill(dsTarget, "DictionaryItem");//將字典值添加到目標數據集
}
dsTarget.Merge(dsSource); //將源數據集的DictionaryType表合併到目標數據集中
GridView1.DataSource = dsTarget.Tables["DictionaryType"];
GridView1.DataBind();
}
學習下。
轉載自:http://www.cnblogs.com/hsw-2013/archive/2013/03/16/2962451.html