把A数据库中的数据导入B数据库中

 SqlConnection conn = new SqlConnection();
            conn.ConnectionString = "server=SDWX-08111023;Integrated Security=true; Initial Catalog=11";
            SqlCommand comm = new SqlCommand();
            comm.Connection = conn;
            conn.Open();
            comm.CommandText = "insert into test select * from MyFirst.dbo.T_test";
            comm.ExecuteNonQuery();
            MessageBox.Show("导入成功!!!");
            comm.CommandText = "select * from test";
            comm.ExecuteNonQuery();
            SqlDataAdapter adapter = new SqlDataAdapter(comm);
            DataTable dt = new DataTable();
            adapter.Fill(dt);
            if (dt.Rows.Count > 0)
            {
                this.dataGridView2.DataSource = dt;
            }
            conn.Close();

你可能感兴趣的:(把A数据库中的数据导入B数据库中)