當前位置: 首頁>>代碼示例>>C#>>正文


C# OracleConnection.CreateCommand方法代碼示例

本文整理匯總了C#中Oracle.DataAccess.Client.OracleConnection.CreateCommand方法的典型用法代碼示例。如果您正苦於以下問題:C# OracleConnection.CreateCommand方法的具體用法?C# OracleConnection.CreateCommand怎麽用?C# OracleConnection.CreateCommand使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Oracle.DataAccess.Client.OracleConnection的用法示例。


在下文中一共展示了OracleConnection.CreateCommand方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: TestConnectionWithString

        public void TestConnectionWithString() 
        {
            int ret = 0;
            string connstring = "Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=pdborcl)));User Id=system;Password=admin1234;";

            string sql = @"select *from user_tables;";
            sql = getSqlString();
//            string sql = @"begin 
//create sequence TABLE22_SEQ;
//create table table22(id NUMBER DEFAULT 1);
//end;";
            using (DbConnection conn = new  OracleConnection(connstring))
            {
                conn.Open();
                DbCommand command = conn.CreateCommand();
                command.CommandType = CommandType.Text;
                command.CommandText = sql;

                ret = command.ExecuteNonQuery();

                conn.Close();
            }

            Assert.AreNotEqual(ret,0);
        }
開發者ID:Aliceljm1,項目名稱:kiss-project.linq,代碼行數:25,代碼來源:EntryPoint.cs

示例2: ADO_NET_Example

        static void ADO_NET_Example()
        {
            var cs = "Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=www.machinejar.com)(PORT=1522)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=devorc02)));User Id=hr;Password=hr;";

            OracleConnection con = new OracleConnection();
            con.ConnectionString = cs;
            con.Open();

            OracleCommand cmd = con.CreateCommand();
            cmd.CommandText = "HR_DEPTPERCOUNTRY";
            cmd.CommandType = System.Data.CommandType.StoredProcedure;

            OracleParameter orcParam = new OracleParameter("CNTR_CD", OracleDbType.Varchar2);
            orcParam.Size = 50;
            orcParam.Value = "UK";
            orcParam.Direction = System.Data.ParameterDirection.Input;
            cmd.Parameters.Add(orcParam);

            OracleParameter orcOutParam = new OracleParameter("RS_CURSOR", OracleDbType.RefCursor);
            orcOutParam.Size = 50;
            orcOutParam.Direction = System.Data.ParameterDirection.Output;
            cmd.Parameters.Add(orcOutParam);

            cmd.ExecuteNonQuery();

            OracleDataReader reader = ((OracleRefCursor)cmd.Parameters["RS_CURSOR"].Value).GetDataReader();

            while (reader.Read())
            {
                Console.WriteLine("Dept Name: {0} | Address: {1}, | Country: {2}", reader.GetString(0), reader.GetString(1), reader.GetString(2));
            }
        }
開發者ID:devworker55,項目名稱:SourceLab,代碼行數:32,代碼來源:Program.cs

示例3: CallFuncWithTable

        /// <summary>
        /// 測試 調用 Oracle 返回結果集的函數.
        /// </summary>
        private void CallFuncWithTable(OracleConnection conn)
        {
            // 創建一個 Command.
            OracleCommand testCommand = conn.CreateCommand();

            // 定義需要執行的SQL語句.
            testCommand.CommandText = "pkg_HelloWorld.getHelloWorld";

            // 定義好,本次執行的類型,是存儲過程.
            testCommand.CommandType = CommandType.StoredProcedure;

            // 定義好,我這個參數,是 遊標 + 返回值.
            OracleParameter para = new OracleParameter("c", OracleDbType.RefCursor);
            para.Direction = ParameterDirection.ReturnValue;
            testCommand.Parameters.Add(para);


            // 執行SQL命令,結果存儲到Reader中.
            OracleDataReader testReader = testCommand.ExecuteReader();

            // 處理檢索出來的每一條數據.
            while (testReader.Read())
            {
                // 將檢索出來的數據,輸出到屏幕上.
                Console.WriteLine("調用函數:{0}; 返回:{1} - {2}",
                    testCommand.CommandText, testReader[0], testReader[1]
                    );
            }

            // 關閉Reader.
            testReader.Close();
        }
開發者ID:mahuidong,項目名稱:my-csharp-sample,代碼行數:35,代碼來源:CallOracleFuncProc.cs

示例4: IsExistsEmail

 public ChangeResultSettings IsExistsEmail(string email)
 {
     var result = new ChangeResultSettings();
     try
     {
         ConnectDB.CloseConnection(_connectGs);
         _connectGs = new OracleConnection();
         _connectGs = ConnectDB.GetOracleConnection(_connectGs);
         var cm = _connectGs.CreateCommand();
         cm.CommandText = "usp_check_exists_email";
         cm.CommandType = CommandType.StoredProcedure;
         cm.Parameters.Add(new OracleParameter("email_check", OracleDbType.Varchar2)).Value = email;
         var op = new OracleParameter("total_result", OracleDbType.Long, 15) { Direction = ParameterDirection.Output };
         cm.Parameters.Add(op);
         cm.ExecuteNonQuery();
         var total = Convert.ToInt32(cm.Parameters["total_result"].Value.ToString());
         switch (total)
         {
             case 0:
                 result.ChangeResult = ChangeResult.ThanhCong;
                 break;
             default:
                 result.ChangeResult = ChangeResult.ThatBai;
                 break;
         }
     }
     catch (Exception ex)
     {
         result.Message = "Có lỗi trong quá trình kiểm tra email. Vui lòng thử lại!";
         result.ChangeResult = ChangeResult.ThatBai;
     }
     return result;
 }
開發者ID:nstungxd,項目名稱:ips-project-vdc,代碼行數:33,代碼來源:UserRepository.cs

示例5: ChiTietDuAn

        public DataTable ChiTietDuAn(string mdv, string nsd, string pas, string maDonVi, long idDuAn)
        {
            try
            {
                ConnectDB.CloseConnection(_connectGs);
                _connectGs = new OracleConnection();
                _connectGs = ConnectDB.GetOracleConnection(_connectGs);
                var cm = _connectGs.CreateCommand();
                cm.CommandText = "usp_ChiTiet_DuAn";
                cm.CommandType = CommandType.StoredProcedure;
                cm.Parameters.Add(new OracleParameter("ma_donvi", OracleDbType.Varchar2)).Value = "";
                cm.Parameters.Add(new OracleParameter("nsd", OracleDbType.Varchar2)).Value = "";
                cm.Parameters.Add(new OracleParameter("pas", OracleDbType.Varchar2)).Value = "";
                cm.Parameters.Add(new OracleParameter("id_duan", OracleDbType.Long)).Value = idDuAn;
                cm.Parameters.Add(new OracleParameter("ma_donvi_thuchien", OracleDbType.Varchar2)).Value = maDonVi;
                cm.Parameters.Add(new OracleParameter("cs_lke", OracleDbType.RefCursor)).Direction =
                    ParameterDirection.Output;

                var tableGs = new DataTable();
                _oracleAdapter = new OracleDataAdapter(cm);
                _oracleAdapter.Fill(tableGs);
                return tableGs;
            }
            catch (Exception)
            {
                return null;
            }
            finally
            {
                ConnectDB.CloseConnection(_connectGs);
            }
        }
開發者ID:nstungxd,項目名稱:ips-project-vdc,代碼行數:32,代碼來源:GiamSatRepository.cs

示例6: CapNhatLoaiNguonVon

 public ChangeResultSettings CapNhatLoaiNguonVon(string mdv, string nsd, string pas, string maDonVi, long idDuAn, int loaiNguonVon)
 {
     var result = new ChangeResultSettings();
     try
     {
         ConnectDB.CloseConnection(_connectGs);
         _connectGs = new OracleConnection();
         _connectGs = ConnectDB.GetOracleConnection(_connectGs);
         var cm = _connectGs.CreateCommand();
         cm.CommandText = "usp_CapNhat_DuAn_LoaiNguonVon";
         cm.CommandType = CommandType.StoredProcedure;
         cm.Parameters.Add(new OracleParameter("ma_donvi", OracleDbType.Varchar2)).Value = "";
         cm.Parameters.Add(new OracleParameter("nsd", OracleDbType.Varchar2)).Value = "";
         cm.Parameters.Add(new OracleParameter("pas", OracleDbType.Varchar2)).Value = "";
         cm.Parameters.Add(new OracleParameter("id_duan", OracleDbType.Long)).Value = idDuAn;
         cm.Parameters.Add(new OracleParameter("ma_donvi_thuchien", OracleDbType.Varchar2)).Value = maDonVi;
         cm.Parameters.Add(new OracleParameter("loai_nguonvon", OracleDbType.Int32)).Value = loaiNguonVon;
         var op = new OracleParameter("row_updated", OracleDbType.Long, 15) { Direction = ParameterDirection.Output };
         cm.Parameters.Add(op);
         cm.ExecuteNonQuery();
         var rowUpdated = cm.Parameters["row_updated"].Value.ToString();
         if (rowUpdated == "0")
             result.ChangeResult = ChangeResult.ThatBai;
     }
     catch (Exception ex)
     {
         result.ChangeResult = ChangeResult.ThatBai;
         result.Message = ex.Message;
         throw;
     }
     return result;
 }
開發者ID:nstungxd,項目名稱:ips-project-vdc,代碼行數:32,代碼來源:GiamSatRepository.cs

示例7: ODPNetConnect

        /// <summary>
        /// Construtor, por default já conecta no banco de dados, caso não queira passe false no parâmetro.
        /// Construct open database connetion by default, if you don't want set startConnection = false
        /// </summary>
        /// <param name="startConnection">
        ///     Conectar no banco de dados, default true
        ///     Open database connection
        /// </param>
        public ODPNetConnect(bool startConnection = false)
        {
            ClearMessages();
            if (!startConnection)
            {
                return;
            }

            myConnection = GetConnection();
            if (!String.IsNullOrWhiteSpace(this.ERROR)) //Erro ao conectar. Connection error
            {
                return;
            }

            try
            {
                if (!myConnection.State.ToString().Equals("Open"))
                {
                    myConnection.Open();
                }

                myCommand = myConnection.CreateCommand();
            }
            catch (Exception e)
            {
                ERROR = e.Message;
                if (e.InnerException != null)
                {
                    ERROR += e.InnerException.Message;
                }
            }
        }
開發者ID:pedro-muniz,項目名稱:ODPNetConnect,代碼行數:40,代碼來源:ODPNetConnect.cs

示例8: ExecuteQuery

        /// <summary>
        /// выполнение запроса к базе
        /// </summary>
        /// <param name="cmdString">строка запроса</param>
        /// <returns>возвращает значение bool выполнено или нет</returns>
        public static bool ExecuteQuery(string cmdString)
        {
            using (var connection = new OracleConnection(GetConnectionString()))
            {
                var cmd = connection.CreateCommand();
                cmd.CommandText = cmdString;
                try
                {
                    connection.Open();
                    var transaction = connection.BeginTransaction();
                    Debug.WriteLine("Соединение открыто");
                    cmd.ExecuteNonQuery();
                    transaction.Commit();
                    Debug.WriteLine("Запрос выполнен");

                }
                catch (OracleException exception)
                {
                    Debug.WriteLine(exception.Message);
                    return false;
                }
                finally
                {
                    connection.Close();
                    Debug.WriteLine("Соединение закрыто");
                }
            }
            return true;
        }
開發者ID:silan4ik,項目名稱:UploadLASFiles,代碼行數:34,代碼來源:Tools.cs

示例9: DatabaseKoppeling

 public DatabaseKoppeling()
 {
     string user = "TURVEN";
     string pw = "FRAGIE";
     conn = new OracleConnection();
     command = conn.CreateCommand();
     conn.ConnectionString = "User Id=" + user + ";Password=" + pw + ";Data Source=" + " //localhost:1521/xe" + ";";
 }
開發者ID:mrhaver,項目名稱:TurfProject,代碼行數:8,代碼來源:DatabaseKoppeling.cs

示例10: Start

        public void Start()
        {
            string connectionString = "Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.3.92)(PORT=1521))(CONNECT_DATA=(SID=XE)));User Id=sa;Password=sa123456;";
            OracleConnection conn = new OracleConnection(connectionString);
            conn.Open();

            OracleCommand cmd = conn.CreateCommand();
            cmd.CommandText = "select * from test";
            IDataReader dr = cmd.ExecuteReader();
        }
開發者ID:hhahh2011,項目名稱:CH.Study,代碼行數:10,代碼來源:OracleTest.cs

示例11: DBReader

 public DBReader(String ConnStr_, String PipeName_)
 {
     using (Logger l = new Logger("PipeCatcher"))
     {
         ConnStr = ConnStr_;
         PipeName = PipeName_;
         OraConn = new OracleConnection(ConnStr);
         OraCmd = OraConn.CreateCommand();
         l.msg("A new DBReader created ConnStr={0} PipeName={1}", ConnStr, PipeName);
     }
 }
開發者ID:pulse-computer-consulting,項目名稱:NucleusPub,代碼行數:11,代碼來源:DBReader.cs

示例12: CreateQueueIfNecessary

 public static void CreateQueueIfNecessary(Address address, string connectionString)
 {
     using (OracleConnection connection = new OracleConnection(connectionString))
     {
         OracleCommand cmd = connection.CreateCommand();
         cmd.CommandText = InstallSql;
         cmd.Parameters.Add("queue", NormalizeQueueName(address));
         cmd.Parameters.Add("queueTable", (NormalizeQueueName(address) + "_tab").ToUpper());
         connection.Open();
         cmd.ExecuteNonQuery();
     }
 }
開發者ID:rosieks,項目名稱:NServiceBus-Contrib,代碼行數:12,代碼來源:OracleAqsUtilities.cs

示例13: GetMessages

        public static List<MessageInfo> GetMessages(string businessId, DBConnection connection)
        {
            var connString = connection.getConnectionString();

               var result = new List<MessageInfo>();

               var output = "npu, correlationNpu, businessid, creationdate, processid, interfacetoinvoke, operation, payload";
               var filter = string.Format(" businessId = '{0}' ", businessId) ;
               var orderBy = " ORDER BY creationdate ASC";

               if (!string.IsNullOrEmpty(Configuration.IgnoreOperations))
               {
               var opers = Configuration.IgnoreOperations.Split(';');

               var formOper = " {0} AND NPU not like '%{1}%' ";

               foreach (var o in opers)
               {
                   filter = string.Format(formOper, filter, o);
               }
               }

               using(OracleConnection conn = new OracleConnection(connString)){

               var command = conn.CreateCommand();

               command.CommandText = connection.CreateQuery(output, "pt_msg_inbound", filter, orderBy);
               conn.Open();

               var reader = command.ExecuteReader();

               while (reader.Read())
               {
                   var msg = MessageInfo.LoadFromDB(reader);
                   result.Add(msg);
               }

               command.CommandText = connection.CreateQuery(output, "pt_msg_inbound_archive", filter, orderBy);
               reader = command.ExecuteReader();

               while (reader.Read())
               {
                   var msg = MessageInfo.LoadFromDB(reader);
                   result.Add(msg);

               }

               }

               result = result.OrderBy(a => a.ReceivedDatetime).ToList();

               return result;
        }
開發者ID:jmacnico,項目名稱:Proxmulator,代碼行數:53,代碼來源:DBAccess.cs

示例14: Init

        /// <summary>
        /// Initializes the message receiver.
        /// </summary>
        /// <param name="address">The address of the message source.</param>
        /// <param name="transactional">Indicates if the receiver should be transactional.</param>
        public void Init(Address address, bool transactional)
        {
            this.inputQueueAddress = OracleAqsUtilities.NormalizeQueueName(address);

            using (OracleConnection conn = new OracleConnection(this.ConnectionString))
            {
                OracleCommand cmd = conn.CreateCommand();
                cmd.CommandText = "SELECT queue_table FROM dba_queues WHERE name = :queue";
                cmd.Parameters.Add("queue", this.inputQueueAddress);
                conn.Open();
                this.queueTable = cmd.ExecuteScalar() as string;
            }
        }
開發者ID:rosieks,項目名稱:NServiceBus-Contrib,代碼行數:18,代碼來源:OracleAqsMessageReceiver.cs

示例15: getResultTable

        public static DataSet getResultTable(OracleConnection conn, string sqlText)
        {
            OracleCommand cmd = conn.CreateCommand();

            cmd.CommandText = sqlText;

            OracleDataAdapter adapter = new OracleDataAdapter(cmd);
            DataSet ds = new DataSet();
            ds.Tables.Add(new DataTable("DbSource"));
            adapter.Fill(ds, "DbSource");

            return ds;
        }
開發者ID:xusheng666,項目名稱:DB_Scheme_Extract,代碼行數:13,代碼來源:OracleClient.cs


注:本文中的Oracle.DataAccess.Client.OracleConnection.CreateCommand方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。