码迷,mamicode.com
首页 > 数据库 > 详细

C#通过OleDb查询Oracle存储过程

时间:2016-11-05 09:25:53      阅读:180      评论:0      收藏:0      [点我收藏+]

标签:apt   protoc   address   dbconnect   security   var   cep   final   command   

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];
        }

  

C#通过OleDb查询Oracle存储过程

标签:apt   protoc   address   dbconnect   security   var   cep   final   command   

原文地址:http://www.cnblogs.com/leon1984/p/6032308.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!