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