如何从C#调用oracle中的存储过程?
请访问由oracle为Microsoft OracleClient Developers设置的ODP网站:http : //www.oracle.com/technetwork/topics/dotnet/index-085703.html
同样在下面是示例代码,可以帮助您开始从C#到Oracle调用存储过程。PKG_COLLECTION.CSP_COLLECTION_HDR_SELECT是在Oracle上构建的存储过程,接受参数PUNIT,POFFICE,PRECEIPT_NBR并将结果返回到T_CURSOR。
using Oracle.DataAccess; using Oracle.DataAccess.Client; public DataTable GetHeader_BySproc(string unit, string office, string receiptno) { using (OracleConnection cn = new OracleConnection(DatabaseHelper.GetConnectionString())) { OracleDataAdapter da = new OracleDataAdapter(); OracleCommand cmd = new OracleCommand(); cmd.Connection = cn; cmd.InitialLONGFetchSize = 1000; cmd.CommandText = DatabaseHelper.GetDBOwner() + "PKG_COLLECTION.CSP_COLLECTION_HDR_SELECT"; cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add("PUNIT", OracleDbType.Char).Value = unit; cmd.Parameters.Add("POFFICE", OracleDbType.Char).Value = office; cmd.Parameters.Add("PRECEIPT_NBR", OracleDbType.Int32).Value = receiptno; cmd.Parameters.Add("T_CURSOR", OracleDbType.RefCursor).Direction = ParameterDirection.Output; da.SelectCommand = cmd; DataTable dt = new DataTable(); da.Fill(dt); return dt; } }