将特定的表行从一个数据库源复制到另一个数据库

时间:2019-11-18 05:15:49

标签: c#

我正在尝试使用C#将特定行从一个数据库的表复制到另一个数据库。我使用DataAdapter.Update(DataSet)功能尝试了以下操作:

using (OleDbConnection sourceConnection = new OleDbConnection(source)){
        using (OleDbConnection destinationConnection = new OleDbConnection(destination))
        {
            sourceConnection.Open();
            destinationConnection.Open();

            OleDbDataAdapter adapter1 = new OleDbDataAdapter();
            adapter1.SelectCommand = new OleDbCommand("SELECT * FROM Table1", sourceConnection);
            adapter1.Fill(dataSet);

            OleDbDataAdapter adapter2 = new OleDbDataAdapter();
            adapter2.SelectCommand = new OleDbCommand("SELECT * FROM Table1", destinationConnection);
            OleDbCommandBuilder builder = new OleDbCommandBuilder(adapter2);
            adapter2.UpdateCommand = builder.GetUpdateCommand();
            adapter2.Update(dataSet);

            sourceConnection.Close();
            destinationConnection.Close();
        }
    }

我如何进行这项工作?

0 个答案:

没有答案