Exemplo n.º 1
0
    public static void Main()
    {
        OracleConnection thisConnection = new OracleConnection(
            @"data source=topcredu;User ID=scott;Password=tiger");

        thisConnection.Open();

        OracleDataAdapter thisAdapter = new
                                        OracleDataAdapter("SELECT * from emp", thisConnection);

        OracleCommandBuilder thisBuilder = new OracleCommandBuilder(thisAdapter);

        Console.WriteLine("SQL SELECT Command is:\n{0}\n",
                          thisAdapter.SelectCommand.CommandText);

        OracleCommand updateCommand = thisBuilder.GetUpdateCommand();

        Console.WriteLine("SQL UPDATE Command is:\n{0}\n",
                          updateCommand.CommandText);

        OracleCommand insertCommand = thisBuilder.GetInsertCommand();

        Console.WriteLine("SQL INSERT Command is:\n{0}\n",
                          insertCommand.CommandText);

        OracleCommand deleteCommand = thisBuilder.GetDeleteCommand();

        Console.WriteLine("SQL DELETE Command is:\n{0}", deleteCommand.CommandText);
        thisConnection.Close();
    }
Exemplo n.º 2
0
        public DbDataAdapter CreateDataAdapter(string selectCommandText, IDbConnection connection)
        {
            var oracleConnection = (OracleConnection)connection;
            var dataAdapter      = new OracleDataAdapter(selectCommandText, oracleConnection);
            var commandBuilder   = new OracleCommandBuilder(dataAdapter);

            try
            {
                dataAdapter.InsertCommand = commandBuilder.GetInsertCommand();
            }
            catch
            {
            }

            try
            {
                dataAdapter.UpdateCommand = commandBuilder.GetUpdateCommand();
            }
            catch
            {
            }

            try
            {
                dataAdapter.DeleteCommand = commandBuilder.GetDeleteCommand();
            }
            catch
            {
            }

            return(dataAdapter);
        }
Exemplo n.º 3
0
        public static void Main()
        {
            string           str            = @"Data Source=(DESCRIPTION =
                                (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.27)(PORT = 1521))
                                                    (CONNECT_DATA =
                                                        (SERVER = DEDICATED)
                                                        (SERVICE_NAME = topcredu)
                                                    )
                                ) ; User Id = scott; Password = tiger";
            OracleConnection thisConnection = new OracleConnection(str);

            thisConnection.Open();

            OracleDataAdapter thisAdapter = new OracleDataAdapter("SELECT * from emp", thisConnection);

            OracleCommandBuilder thisBuilder = new OracleCommandBuilder(thisAdapter);

            Console.WriteLine("SQL SELECT Command is:\n{0}\n", thisAdapter.SelectCommand.CommandText);

            OracleCommand updateCommand = thisBuilder.GetUpdateCommand();

            Console.WriteLine("SQL UPDATE Command is:\n{0}\n", updateCommand.CommandText);

            OracleCommand insertCommand = thisBuilder.GetInsertCommand();

            Console.WriteLine("SQL INSERT Command is:\n{0}\n", insertCommand.CommandText);

            OracleCommand deleteCommand = thisBuilder.GetDeleteCommand();

            Console.WriteLine("SQL DELETE Command is:\n{0}", deleteCommand.CommandText);
            thisConnection.Close();
        }
Exemplo n.º 4
0
        void comboBox_CurrentChanged(string curItem)
        {
            //string curItem = (string)sender;
            string sql = @"select * from  tracker_tb_vl where sgroup = '%group%' and prj = 'BPGOM' order by 1,2".Replace("%group%", curItem);

            try
            {
                //ds = New DataSet("sGroup")
                da_sGroup = new OracleDataAdapter(sql, cnn);
                da_sGroup.AcceptChangesDuringUpdate = true;
                OracleCommandBuilder cb = new OracleCommandBuilder(da_sGroup);

                //set_upd_cmd()
                da_sGroup.UpdateCommand = cb.GetUpdateCommand();

                da_sGroup.InsertCommand = cb.GetInsertCommand();
                da_sGroup.DeleteCommand = cb.GetDeleteCommand();



                DataTable dt = MyDb.Oracle.sql2DT(sql, (System.Data.Common.DbConnection)cnn);
                dt.TableName = "sGroup";
                ds           = new DataSet("sGroup");
                ds.Tables.Add(dt);
                //Class_Db_Oracle.get_crud(ref canInsert, ref canSelect, ref canUpdate, ref canDelete, wbs,
                //    Class_Common.CurrentUserDisc(xMainWindow), cnn);//.ParentForm), cnn);

                xDataGrid.DataSource = ds.Tables["sGroup"].DefaultView; //ultraGrid1.DataMember = "sGroup";
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// 단일 실행형(일부 컬럼만 업데이트 할때)
        /// </summary>
        /// <param name="dt">업데이트할 테이블</param>
        /// <param name="strColNm">수정할 컬럼이름</param>
        /// <returns></returns>
        public int updateTable(DataTable dt, string strTableName, string strColNm)
        {
            int affectRow = 0;
            OracleCommandBuilder cb;

            this.oDataAdapter = new OracleDataAdapter("SELECT " + strColNm + " FROM " + strTableName, this.oConn);
            cb = new OracleCommandBuilder(this.oDataAdapter);

            this.oDataAdapter.DeleteCommand = cb.GetDeleteCommand();
            this.oDataAdapter.InsertCommand = cb.GetInsertCommand();
            this.oDataAdapter.UpdateCommand = cb.GetUpdateCommand();
            try
            {
                this.oConn.Open();
                this.oTr = this.oConn.BeginTransaction();
                this.oDataAdapter.DeleteCommand.Transaction = this.oTr;
                this.oDataAdapter.InsertCommand.Transaction = this.oTr;
                this.oDataAdapter.UpdateCommand.Transaction = this.oTr;

                affectRow = this.oDataAdapter.Update(dt);
                this.oTr.Commit();
                return(affectRow);
            }
            catch (Exception ex)
            {
                this.oTr.Rollback();
                this.oConn.Close();
                throw new Exception("DB 업로드 오류", ex);
            }
        }
Exemplo n.º 6
0
        public void test()
        {
            OracleDataAdapter da = new OracleDataAdapter("SELECT * FROM BARANG", conn.c);

            OracleCommandBuilder cb = new OracleCommandBuilder(da);

            Console.WriteLine();
            Console.WriteLine(cb.GetInsertCommand().CommandText);
            Console.WriteLine();
            Console.WriteLine(cb.GetUpdateCommand().CommandText);
            Console.WriteLine();
            Console.WriteLine();
            Console.WriteLine(cb.GetDeleteCommand().CommandText);
            Console.WriteLine();
            //OracleCommand cmd = cb.GetInsertCommand();
            //cmd.Parameters.Add("aku");
            //cmd.Parameters.Add("aku");
            //cmd.Parameters.Add("aku");
            //cmd.Parameters.Add("aku");
            //cmd.Parameters.Add("aku");
            //cmd.Parameters.Add("aku");
            //cmd.Parameters.Add(1);
            //cmd.Parameters.Add("aku");
            //cmd.Parameters.Add(2);
            //cmd.Parameters.Add(1);
            //cmd.ExecuteNonQuery();
        }
Exemplo n.º 7
0
        public short Update(Hashtable HTable, string SourceTableName, string Filter, OracleConnection Conn)
        {
            try
            {
                Cmnd = new OracleCommand("SELECT * FROM " + SourceTableName + " WHERE " + Filter, Conn);
                OracleDataAdapter ADP = new OracleDataAdapter(Cmnd);
                DataSet           DS  = new DataSet();
                ADP.Fill(DS, SourceTableName);
                int rowNumber = 0;
                for (int i = 0; i < DS.Tables[0].Rows.Count; i++)
                {
                    DataRow DR_UPDATE = DS.Tables[0].Rows[rowNumber];
                    foreach (object OBJ in HTable.Keys)
                    {
                        string COLUMN_NAME = Convert.ToString(OBJ);
                        DR_UPDATE[COLUMN_NAME] = HTable[OBJ];
                    }
                    OracleCommandBuilder BLD = new OracleCommandBuilder(ADP);
                    ADP.UpdateCommand = BLD.GetUpdateCommand();
                    ADP.Update(DS, SourceTableName);
                    rowNumber++;
                }

                return(1);
            }
            catch (OracleException Ex)
            {
                if (Trans != null)
                {
                    Trans.Rollback();
                    Trans = null;
                }

                throw Ex;
            }

            catch (Exception Ex)
            {
                if (Trans != null)
                {
                    Trans.Rollback();
                    Trans = null;
                }

                throw Ex;
            }
            finally
            {
                if (Trans == null)
                {
                    CloseAppConnection();
                }
            }
        }
Exemplo n.º 8
0
        ////////////////////////////////////////////////////
        public override IDbCommand GetUpdateCommand(DataTable table, IDbDataAdapter adapter)
        {
            OracleCommandBuilder builder = new OracleCommandBuilder((OracleDataAdapter)adapter);
            OracleCommand        command = builder.GetUpdateCommand();

            if (m_connexion.IsInTrans())
            {
                command.Transaction = (OracleTransaction)m_connexion.Transaction;
            }
            return(command);
        }
Exemplo n.º 9
0
 public void UpdateContentOfTable(string tableName, DataTable content)
 {
     using (var c = _connection.CreateCommand())
     {
         c.CommandText = string.Format("select * from {0}", tableName);
         using (var adapter = new OracleDataAdapter(c))
         {
             using (var builder = new OracleCommandBuilder(adapter))
             {
                 adapter.UpdateCommand = builder.GetUpdateCommand();
                 adapter.Update(content);
             }
         }
     }
 }
Exemplo n.º 10
0
 public void UpdateTableContent(string tableName, DataTable table)
 {
     using (OracleCommand command = _connection.CreateCommand( ))
     {
         command.CommandText = string.Format("select * from {0}", tableName);
         using (OracleDataAdapter adapter = new OracleDataAdapter(command))
         {
             using (OracleCommandBuilder builder = new OracleCommandBuilder(adapter))
             {
                 adapter.UpdateCommand = builder.GetUpdateCommand( );
                 adapter.InsertCommand = builder.GetInsertCommand( );
                 adapter.DeleteCommand = builder.GetDeleteCommand( );
                 adapter.Update(table);
             }
         }
     }
 }
Exemplo n.º 11
0
        /// <summary>
        /// Update Multi Table
        /// </summary>
        /// <param name="ds">Multi Update Data</param>
        /// <param name="sqlList">Multi Select sql</param>
        /// <returns></returns>
        public ResultData UpdateMultiTable(List <DataTable> ds, List <string> sqlList)
        {
            var connection = CreateConnection();
            OracleConnection oracleConn = (OracleConnection)connection;

            OracleTransaction tran       = oracleConn.BeginTransaction(IsolationLevel.ReadCommitted);
            ResultData        resultData = new ResultData();

            resultData.Status = ResultStatus.Fail;

            try {
                foreach (DataTable inputDt in ds)
                {
                    OracleCommand     command     = new OracleCommand(sqlList[ds.IndexOf(inputDt)], oracleConn);
                    OracleDataAdapter dataAdapter = new OracleDataAdapter();
                    dataAdapter.SelectCommand = command;

                    OracleCommandBuilder commandBuilder = new OracleCommandBuilder(dataAdapter);
                    dataAdapter.InsertCommand = commandBuilder.GetInsertCommand();
                    dataAdapter.UpdateCommand = commandBuilder.GetUpdateCommand();
                    dataAdapter.DeleteCommand = commandBuilder.GetDeleteCommand();
                    command.Transaction       = tran;

                    int rows = dataAdapter.Update(inputDt);

                    if (rows >= 1)
                    {
                        resultData.Status = ResultStatus.Success;
                    }
                    else
                    {
                        tran.Rollback();
                        return(resultData);
                    }
                }
                tran.Commit();
            } catch (Exception ex) {
                tran.Rollback();
                throw ex;
            }
            return(resultData);
        }
Exemplo n.º 12
0
 public bool Save(DataTable dt, out int i)
 {
     try
     {
         OracleDataAdapter oda          = new OracleDataAdapter();
         StringBuilder     selectOracle = new StringBuilder(256);
         selectOracle.AppendFormat(" Select * From {0} Where 1!=1 ", dt.TableName);
         OracleCommand selectCommand = new OracleCommand(selectOracle.ToString(), Connection);
         selectCommand.Transaction = Tran;
         oda.SelectCommand         = selectCommand;
         OracleCommandBuilder ocb = new OracleCommandBuilder(oda);
         oda.InsertCommand = ocb.GetInsertCommand();
         oda.UpdateCommand = ocb.GetUpdateCommand();
         i = oda.Update(dt);
         return(true);
     }
     catch
     {
         throw;
     }
 }
Exemplo n.º 13
0
        public override void Update(System.Data.DataTable data, string selectsql)
        {
            if (_s == DBStatus.Close)
            {
                DoOpen();
            }

            OracleCommand cmd;

            using (cmd = new OracleCommand(selectsql, conn))
            {
                if (cmd.Connection.State == ConnectionState.Closed)
                {
                    cmd.Connection.Open();
                }

                if (this._s == DBStatus.Begin_Trans)
                {
                    cmd.Transaction = this.tran;
                }

                OracleDataAdapter    adt     = new OracleDataAdapter(cmd);
                OracleCommandBuilder builder = new OracleCommandBuilder(adt);

                try
                {
                    adt.UpdateCommand = builder.GetUpdateCommand();
                    adt.Update(data);
                }
                catch (Exception ex)
                {
                    throw ex;
                }
                finally
                {
                    cmd.Cancel();
                    cmd = null;
                }
            }
        }
Exemplo n.º 14
0
        //연속실행형

        public void updateDataSet(DataSet ds)
        {
            //DataTable dt;
            int i = 0;
            OracleCommandBuilder cb;

            OracleDataAdapter[] oDA = new OracleDataAdapter[ds.Tables.Count];
            foreach (DataTable dt in ds.Tables)
            {
                oDA[i] = new OracleDataAdapter("SELECT * FROM " + dt.TableName, this.oConn);
                cb     = new OracleCommandBuilder(oDA[i]);
                oDA[i].DeleteCommand = cb.GetDeleteCommand();
                oDA[i].InsertCommand = cb.GetInsertCommand();
                oDA[i].UpdateCommand = cb.GetUpdateCommand();
                i++;
            }

            try
            {
                i = 0;
                this.oConn.Open();
                this.oTr = this.oConn.BeginTransaction();
                foreach (DataTable updateTable in ds.Tables)
                {
                    oDA[i].DeleteCommand.Transaction = this.oTr;
                    oDA[i].InsertCommand.Transaction = this.oTr;
                    oDA[i].UpdateCommand.Transaction = this.oTr;

                    oDA[i].Update(updateTable);
                    i++;
                }
                this.oTr.Commit();
            }
            catch (Exception oErr)
            {
                this.oTr.Rollback();
                this.oConn.Close();
                throw oErr;
            }
        }
Exemplo n.º 15
0
        /// <summary>
        /// use oraclecommand update DB by sql string and update column
        /// </summary>
        /// <param name="inputDT"></param>
        /// <param name="sql"></param>
        /// <returns></returns>
        public ResultData UpdateOracleDB(DataTable inputDT, string sql)
        {
            var connection = CreateConnection();
            OracleConnection oracleConn = (OracleConnection)connection;

            OracleCommand     command    = new OracleCommand(sql, oracleConn);
            OracleTransaction tran       = oracleConn.BeginTransaction(IsolationLevel.ReadCommitted);
            ResultData        resultData = new ResultData();

            resultData.Status   = ResultStatus.Fail;
            command.Transaction = tran;

            try {
                OracleDataAdapter dataAdapter = new OracleDataAdapter();
                dataAdapter.SelectCommand = command;

                OracleCommandBuilder commandBuilder = new OracleCommandBuilder(dataAdapter);
                dataAdapter.InsertCommand = commandBuilder.GetInsertCommand();
                dataAdapter.UpdateCommand = commandBuilder.GetUpdateCommand();
                dataAdapter.DeleteCommand = commandBuilder.GetDeleteCommand();

                int rows = dataAdapter.Update(inputDT);

                if (rows >= 1)
                {
                    tran.Commit();
                    resultData.Status = ResultStatus.Success;
                    return(resultData);
                }
                else
                {
                    tran.Rollback();
                    return(resultData);
                }
            } catch (Exception ex) {
                tran.Rollback();
                throw ex;
            }
        }
Exemplo n.º 16
0
        /// <summary>
        /// 表批量写入
        /// 根据行数据 RowState 状态新增、修改
        /// </summary>
        /// <param name="dt">数据表</param>
        /// <param name="sqlEmpty">查询空表脚本,默认*,可选列,会影响数据更新的列</param>
        /// <param name="dataAdapter">执行前修改(命令行脚本、超时等信息)</param>
        /// <param name="openTransaction">开启事务,默认开启</param>
        /// <returns></returns>
        public int BulkBatchOracle(DataTable dt, string sqlEmpty = null, Action <OracleDataAdapter> dataAdapter = null, bool openTransaction = true)
        {
            return(SafeConn(() =>
            {
                var connection = (OracleConnection)Connection;
                OracleTransaction transaction = openTransaction ? (OracleTransaction)(Transaction = connection.BeginTransaction()) : null;

                var cb = new OracleCommandBuilder();
                if (string.IsNullOrWhiteSpace(sqlEmpty))
                {
                    var sntn = SqlSNTN(dt.TableName, dt.Namespace, SharedEnum.TypeDB.Oracle);
                    sqlEmpty = SqlEmpty(sntn);
                }

                cb.DataAdapter = new OracleDataAdapter
                {
                    SelectCommand = new OracleCommand(sqlEmpty, connection)
                };
                cb.ConflictOption = ConflictOption.OverwriteChanges;

                var da = new OracleDataAdapter
                {
                    InsertCommand = cb.GetInsertCommand(true),
                    UpdateCommand = cb.GetUpdateCommand(true)
                };
                da.InsertCommand.CommandTimeout = 300;
                da.UpdateCommand.CommandTimeout = 300;

                //执行前修改
                dataAdapter?.Invoke(da);

                var num = da.Update(dt);

                transaction?.Commit();

                return num;
            }));
        }
Exemplo n.º 17
0
        /// <summary>
        /// Custom Fill DataTable
        /// </summary>
        /// <exception cref="ConnectionException"></exception>
        /// <exception cref="AssortmentException"></exception>
        /// <param name="table">Table object</param>
        /// <param name="clearBeforeFill">true default clear DataTable</param>
        public void FillDataTableCustom(Table table, bool clearBeforeFill = true)
        {
            if (Connection.State != ConnectionState.Open) throw new ConnectionException("Соединение не установлено");
            if (_adapters[table.Name] == null)
            {
                _adapters.Add(table.Name, new OracleDataAdapter());
            }
            if (_dataSet.Tables.Contains(table.Name))
            {
                if (clearBeforeFill)
                {
                    DataTableClear(table.Name);
                }
            }
            try
            {
                var cmd = Connection.CreateCommand();
                cmd.CommandText = table.SelectClause;

                ((OracleDataAdapter)_adapters[table.Name]).SelectCommand = cmd;
                ((OracleDataAdapter)_adapters[table.Name]).Fill(_dataSet, table.Name);
                var builder = new OracleCommandBuilder((OracleDataAdapter)_adapters[table.Name]);
                ((OracleDataAdapter)_adapters[table.Name]).UpdateCommand = builder.GetUpdateCommand();

                // Create single (multiple-column) primary key if not exists
                if (_dataSet.Tables[table.Name].PrimaryKey.Length == 0)
                {
                    //foreach (var keyField in table.KeyFields)
                    //{
                    //    keyFields.Add(new DataColumn(keyField));
                    //}

                    _dataSet.Tables[table.Name].PrimaryKey = table.KeyFields.Select(field => _dataSet.Tables[table.Name].Columns[field]).ToArray();

                    //_dataSet.Tables[table.Name].PrimaryKey = table.KeyFields.Select(keyField => new DataColumn(keyField)).ToArray();
                }
            }
            catch (Exception ex)
            {
                throw new AssortmentException(ex.Message);
            }
        }
Exemplo n.º 18
0
        public OracleDataAdapter GetDataAdapterForOracle(string Sql, List <ReportFilter> Filter = null)
        {
            OracleConnection     conn = null;
            OracleDataAdapter    adp  = null;
            OracleCommandBuilder cmdb = null;

            try
            {
                ConnectionDriversConfig driversConfig = DMEEditor.Utilfunction.LinkConnection2Drivers(Dataconnection.ConnectionProp);


                //string adtype = Dataconnection.DataSourceDriver.AdapterType;
                //string cmdtype = Dataconnection.DataSourceDriver.CommandBuilderType;
                //string cmdbuildername = driversConfig.CommandBuilderType;
                //Type adcbuilderType = Type.GetType("OracleCommandBuilder");
                //List<ConstructorInfo> lsc = DMEEditor.assemblyHandler.GetInstance(adtype).GetType().GetConstructors().ToList(); ;
                //List<ConstructorInfo> lsc2 = DMEEditor.assemblyHandler.GetInstance(cmdbuildername).GetType().GetConstructors().ToList(); ;

                //ConstructorInfo ctor = lsc[GetCtorForAdapter(lsc)];
                //ConstructorInfo BuilderConstructer = lsc2[GetCtorForCommandBuilder(adcbuilderType.GetConstructors().ToList())];
                //ObjectActivator<Oracle.ManagedDataAccess.Client.OracleDataAdapter> adpActivator = GetActivator<Oracle.ManagedDataAccess.Client.OracleDataAdapter>(ctor);
                //ObjectActivator<Oracle.ManagedDataAccess.Client.OracleCommandBuilder> cmdbuilderActivator = GetActivator<Oracle.ManagedDataAccess.Client.OracleCommandBuilder>(BuilderConstructer);
                //create an instance:
                // adp = OracleDataAdapter( RDBMSConnection.DbConn);
                conn = (OracleConnection)RDBMSConnection.DbConn;
                adp  = new OracleDataAdapter(Sql, conn);
                cmdb = new OracleCommandBuilder(adp);

                try
                {
                    //Oracle.ManagedDataAccess.Client.OracleCommand cmdBuilder = cmdbuilderActivator(adp);
                    if (Filter != null)
                    {
                        if (Filter.Count > 0)
                        {
                            if (Filter.Where(p => !string.IsNullOrEmpty(p.FilterValue) && !string.IsNullOrWhiteSpace(p.FilterValue) && !string.IsNullOrEmpty(p.Operator) && !string.IsNullOrWhiteSpace(p.Operator)).Any())
                            {
                                foreach (ReportFilter item in Filter.Where(p => !string.IsNullOrEmpty(p.FilterValue) && !string.IsNullOrWhiteSpace(p.FilterValue)))
                                {
                                    OracleParameter parameter = adp.SelectCommand.CreateParameter();
                                    string          dr        = Filter.Where(i => i.FieldName == item.FieldName).FirstOrDefault().FilterValue;
                                    parameter.ParameterName = "p_" + item.FieldName;
                                    if (item.valueType == "System.DateTime")
                                    {
                                        parameter.DbType = DbType.DateTime;
                                        parameter.Value  = DateTime.Parse(dr).ToShortDateString();
                                    }
                                    else
                                    {
                                        parameter.Value = dr;
                                    }

                                    if (item.Operator.ToLower() == "between")
                                    {
                                        OracleParameter parameter1 = adp.SelectCommand.CreateParameter();
                                        parameter1.ParameterName = "p_" + item.FieldName + "1";
                                        parameter1.DbType        = DbType.DateTime;
                                        string dr1 = Filter.Where(i => i.FieldName == item.FieldName).FirstOrDefault().FilterValue1;
                                        parameter1.Value = DateTime.Parse(dr1).ToShortDateString();
                                        adp.SelectCommand.Parameters.Add(parameter1);
                                    }

                                    //  parameter.DbType = TypeToDbType(tb.Columns[item.fieldname].DataType);
                                    adp.SelectCommand.Parameters.Add(parameter);
                                }
                            }
                        }
                    }

                    //  adp.ReturnProviderSpecificTypes = true;
                    adp.SuppressGetDecimalInvalidCastException = true;
                    adp.InsertCommand = cmdb.GetInsertCommand(true);
                    adp.UpdateCommand = cmdb.GetUpdateCommand(true);
                    adp.DeleteCommand = cmdb.GetDeleteCommand(true);
                }
                catch (Exception ex)
                {
                    // DMEEditor.AddLogMessage("Fail", $"Error in Creating builder commands {ex.Message}", DateTime.Now, -1, ex.Message, Errors.Failed);
                }

                adp.MissingSchemaAction  = MissingSchemaAction.AddWithKey;
                adp.MissingMappingAction = MissingMappingAction.Passthrough;


                ErrorObject.Flag = Errors.Ok;
            }
            catch (Exception ex)
            {
                DMEEditor.AddLogMessage("Fail", $"Error in Creating Adapter {ex.Message}", DateTime.Now, -1, ex.Message, Errors.Failed);
                adp = null;
            }

            return(adp);
        }
Exemplo n.º 19
0
        //oracle连接
        public void UpdateData()
        {
            System.Data.OracleClient.OracleTransaction sqltran;
            //将事务绑定到连接对像
            //init.DBConnect();
            try
            {
                //writeLog.Write("" + dtSave.Count, "log");
                using (OracleConnection connection = new OracleConnection(OracleHelper.GetConnectionstring()))
                {
                    sqltran = connection.BeginTransaction();// ConnectDB.con.BeginTransaction();
                    for (int i = 0; i < dtSave.Count; i++)
                    {
                        OracleDataAdapter    adapter    = new OracleDataAdapter(selectStr[i], connection);
                        OracleCommandBuilder cmdBuilder = new OracleCommandBuilder(adapter);

                        try
                        {
                            adapter.SelectCommand = new OracleCommand(selectStr[i], ConnectDB.con, sqltran);
                            adapter.InsertCommand = cmdBuilder.GetInsertCommand();
                            adapter.UpdateCommand = cmdBuilder.GetUpdateCommand();

                            if (dtSave[i].Select(null, null, DataViewRowState.Deleted).Length > 0)
                            {
                                adapter.Update(dtSave[i].Select(null, null, DataViewRowState.Deleted));
                            }
                            if (dtSave[i].Select(null, null, DataViewRowState.ModifiedCurrent).Length > 0)
                            {
                                adapter.Update(dtSave[i].Select(null, null, DataViewRowState.ModifiedCurrent));
                            }
                            if (dtSave[i].Select(null, null, DataViewRowState.Added).Length > 0)
                            {
                                adapter.Update(dtSave[i].Select(null, null, DataViewRowState.Added));
                            }
                        }
                        catch (Exception ex)
                        {
                            writeLog.Write("UpdateData处理:" + ex.Message, "log");
                        }
                    }
                    try
                    {
                        sqltran.Commit();
                    }
                    catch (Exception ex1)
                    {
                        sqltran.Rollback();
                        writeLog.Write("事务提交失败:" + ex1.Message, "log");
                    }
                    finally
                    {
                        connection.Close();
                        connection.Dispose();
                    }
                }
                for (int i = 0; i < strGraph.Count; i++)
                {
                    //writeLog.Write(strGraph[i].ToString(), "log");
                    System.IO.FileStream fs = new System.IO.FileStream(strGraph[i].ToString(), System.IO.FileMode.OpenOrCreate);
                    byte[] blob             = new byte[fs.Length];
                    fs.Read(blob, 0, blob.Length);
                    fs.Close();

                    strUpdateSQL = "update test_graph_result set GRAPH_RESULT = :Photo where GRAPH_RESULT_ID = '" + strGraphID[i] + "'";
                    OracleCommand   oraCmd = new OracleCommand(strUpdateSQL, ConnectDB.con);
                    OracleParameter op     = new OracleParameter("Photo", OracleType.Blob);
                    op.Value = blob;
                    oraCmd.Parameters.Add(op);
                    try
                    {
                        oraCmd.ExecuteNonQuery();
                    }
                    catch (Exception ex)
                    {
                        writeLog.Write("UpdateDataIO处理:" + ex.Message, "log");
                    }
                }
            }
            catch (System.Data.OracleClient.OracleException sqlex)
            {
                // sqltran.Rollback();
                writeLog.Write("UpdateData_sqlex:" + sqlex.Message, "log");
                //return sqlex.Message;
            }
            catch (Exception ex)
            {
                // sqltran.Rollback();
                writeLog.Write("UpdateData_catch:" + ex.Message, "log");
                //return ex.Message;
            }
            finally
            {
                sqltran = null;
            }
        }
Exemplo n.º 20
0
 /// <summary>
 /// ����selectedCommandText�����OracleDataAdapter���󡣲��Զ�����
 /// InsertCommand��DeleteCommand��UpdateCommand
 /// </summary>
 /// <param name="selectedCommandText">selectedCommandText</param>
 /// <returns>The SqlDataAdapter</returns>
 public override IDbDataAdapter GetDataAdapter(string selectCommandText, IDbConnection connection)
 {
     OracleDataAdapter adapter = new OracleDataAdapter(selectCommandText,(OracleConnection)connection);
     adapter.MissingSchemaAction = MissingSchemaAction.AddWithKey;
     using(OracleCommandBuilder builder = new OracleCommandBuilder(adapter))
     {
         adapter.InsertCommand = (OracleCommand)((ICloneable)builder.GetInsertCommand()).Clone();
         adapter.DeleteCommand = (OracleCommand)((ICloneable)builder.GetDeleteCommand()).Clone();
         adapter.UpdateCommand = (OracleCommand)((ICloneable)builder.GetUpdateCommand()).Clone();
     }
     return adapter;
 }