如何连接来自一个数据库的查询结果并将其插入 ac# 应用程序中的另一个?
这是我到目前为止所拥有的,但它不起作用。
// select from first database
string sCMD_All = "SELECT * FROM table";
SqlDataAdapter da = new SqlDataAdapter();
DataSet ds = new DataSet();
using (SqlConnection myConn = new SqlConnection(ConnectionString))
{
using (SqlCommand myCommand = new SqlCommand(sCMD_All, myConn))
{
myConn.Open();
SqlDataReader reader = myCommand.ExecuteReader();
da.Fill(ds);
myConn.Close();
}
}
DataTable sqTable = ds.Tables[0];
//insert into 2nd database
DataTable newTable = new DataTable();
newTable = sqTable;
using (SqlConnection myConn = new SqlConnection(ConnectionString_M))
{
string sCMD_I = "INSERT INTO tableNew @newTable";
using (SqlCommand myCommand = new SqlCommand(sCMD_I, myConn))
{
myConn.Open();
SqlDataReader reader = myCommand.ExecuteReader();
myConn.Close();
}
}