日期:2014-05-17 浏览次数:20975 次
DataSet set = new DataSet();
string strConnection = @"Data Source=.\SQLExpress;Initial Catalog=DB_Person;Integrated Security=True";
using(SqlConnection connect = new SqlConnection(strConnection)) {
SqlCommand cmd = connect.CreateCommand();
cmd.CommandText = "select * from [dbo].[T_Employee_01]"; //从表1获取.
SqlDataAdapter adapterEmployee_01 = new SqlDataAdapter(cmd);
adapterEmployee_01.Fill(set, "Employee_01");
cmd.CommandText = "select * from [dbo].[T_Employee_02]"; //从表2获取.
SqlDataAdapter adapterEmployee_02 = new SqlDataAdapter(cmd);
adapterEmployee_02.Fill(set, "Employee_02");
DataTable T_Employee_01 = set.Tables["Employee_01"];
DataTable T_Employee_02 = set.Tables["Employee_02"];
T_Employee_01.Merge(T_Employee_02, true, MissingSchemaAction.AddWithKey); //表的合并.
dataGV.DataSource = T_Employee_02; //指定DataGridView数据源.
}
//最后不管我指定的数据源是两个表中的任何一个,数据都是 T_Employee_01;为什么没有合并两个表(这两个表字段完全一个样的....