如何使用C#在Oracle表之间传输数据?

时间:2017-10-03 05:32:58

标签: c# oracle

我试图在C#中复制以下简单的SQL语句:

INSERT INTO T1 SELECT * FROM T2;

有一点需要注意的是,T1和T2不仅在不同的模式和数据库中,而且在不同的服务器中,并且dblink不是一个选项。

我在网上找到的所有文档和示例都使用了明确的列名,我在设计时并不知道(我依靠脚本的调用者来确保T1和T2兼容;如果不,我只是回复一个错误。)

以下是我一直在玩的基本代码;阅读部分工作得很好,但写作部分根本不起作用(没有异常抛出,执行完成但T2没有填充):

        OracleDataAdapter od = new OracleDataAdapter();

        tr.SourceConnection.Open();
        OracleCommand selectCommand = BuildCommand(tr.SourceConnection, string.Format("SELECT * FROM {0}", tr.SourceTable));
        od.SelectCommand = selectCommand;
        DataTable srcTb = new DataTable(tr.SourceTable);
        od.Fill(srcTb);
        tr.SourceConnection.Close();

        // Everything works well up to here, so "SELECT * FROM {0}" seems to be the right query

        tr.TargetConnection.Open();
        DataTable tgtTb = new DataTable(tr.TargetTable);
        OracleCommand insertCommand = BuildCommand(tr.TargetConnection, string.Format("INSERT INTO {0}", tr.TargetTable));
        od.InsertCommand = insertCommand;
        od.Update(tgtTb);
        tr.TargetConnection.Close();

        // The data doesn't get pushed to the DB table; what do I need to use instead of "INSERT INTO {0}"?
        // Or do I need a totally different approach?

提前多多感谢!

0 个答案:

没有答案
相关问题