如何从一个数据库表中获取 select 语句的结果并将其插入到另一个数据库表中 - 使用 C#?
问题是我需要在 C# 代码中使用 2 个不同的连接字符串。这是我到目前为止但没有工作的..
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 server 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();
}
}
问题是我需要在 C# 代码中使用 2 个不同的连接字符串。这是我到目前为止但没有工作的..
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 server 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();