c#如何合並兩個數據庫表格
表1.tb_1 表2.tb_2
將表1和2合並
代碼:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
SqlConnection conn;
private void Form1_Load(object sender, EventArgs e)
{
conn = new SqlConnection("server=.;database=k;uid=sa;pwd=123456");
DataSet ds = new DataSet();
DataSet ds1 = new DataSet();
SqlDataAdapter sda = new SqlDataAdapter("select * from tb_1", conn);
sda.Fill(ds);
SqlDataAdapter sda1 = new SqlDataAdapter("select * from tb_2", conn);
SqlCommandBuilder sbl = new SqlCommandBuilder(sda1);
sda1.Fill(ds1);
ds1.Merge(ds,true,MissingSchemaAction.AddWithKey);
dataGridView1.DataSource = ds1.Tables[0];
}
c#如何合並兩個數據庫表格