日期:2014-05-17  浏览次数:21278 次

c# datatable批量更新到oracle数据库
直接看代码:
public static int OracleCopyDataTable(string table,DataTable dt, OracleConnection connOracle)
        {
            try
            {
                string strfields = "";
                string strvalues = "";
                string filed = "";
                string strvalue = "";
                int count = 0;

                OracleDataAdapter da = new OracleDataAdapter();

                OracleCommandBuilder ob = new OracleCommandBuilder(da);

                da.InsertCommand = new OracleCommand();

                for (int i = 0; i < dt.Columns.Count; i++)
                {
                    string strfiled = dt.Columns[i].ColumnName;
                    strfields += strfiled + ",";
                    strvalues += "@" + strfiled + ",";
                }

                if (strfields != "")
                {
                    strfields = strfields.Substring(0, strfields.LastIndexOf(","));
                    strvalues = strvalues.Substring(0, strvalues.LastIndexOf(","));
                }

                da.SelectCommand = new OracleCommand();
                da.SelectCommand.Connection = connOracle;
                da.SelectCommand.CommandText = "select id," + strfields + " from " + table;
                da.InsertCommand.CommandTe