程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> .NET網頁編程 >> C# >> C#入門知識 >> C#通過OleDb查詢Oracle存儲過程,

C#通過OleDb查詢Oracle存儲過程,

編輯:C#入門知識

C#通過OleDb查詢Oracle存儲過程,


using System;
using System.Data;
using System.Data.OleDb;

  

        /// <summary>
        /// 通過OleDb查詢Oracle存儲過程
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public static DataTable getTodoList(string id)
        {
            string connString1 = "provider=OraOLEDB.Oracle.1;User ID=test;Password=test;Data Source=(DESCRIPTION = (ADDRESS_LIST= (ADDRESS = (PROTOCOL = TCP)(HOST = 127.0.0.1)(PORT = 1521))) (CONNECT_DATA = (SERVICE_NAME = orcl)));Persist Security Info=True;Extended Properties='PLSQLRSet=1';";//'PLSQLRSet=1'很重要

            DataSet ds = new DataSet();
            DataTable dt = new DataTable();
            OleDbConnection conn = new OleDbConnection(connString1);
            OleDbCommand cmd = new OleDbCommand("getTodoList", conn);
            cmd.CommandType = CommandType.StoredProcedure;

            try
            {
                conn.Open();

                OleDbParameter[] parms = {
                                         new OleDbParameter("id1", OleDbType  .VarChar)
                                     };
                parms[0].Value = id;
                parms[0].Direction = ParameterDirection.Input;
                foreach (OleDbParameter parm in parms)
                {
                    cmd.Parameters.Add(parm);
                }

                OleDbDataAdapter oda = new OleDbDataAdapter(cmd);

                oda.Fill(ds);

            }
            catch (Exception ex)
            {

            }
            finally
            {
                cmd.Dispose();
                conn.Close();
            }

            return ds.Tables[0];
        }

  

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved