我在Oracle和vb.net中有以下代码和存储过程。当我执行代码时,数据集不返回任何内容。
代码背后:
grvResults.PageSize = DirectCast(Profile.GetPropertyValue("rowcount"), Integer)
grvResults.DataSourceID = "dsResults"
datasource:
public static DataSet Fetch(string sp, OracleParameter[] inputParams)
{
OracleConnection conn = new OracleConnection(System.Configuration.ConfigurationManager.AppSettings.Get("BertConnection"));
cmd = new OracleCommand(sp, conn);
cmd.CommandType = CommandType.StoredProcedure;
if (inputParams != null)
{
cmd.Parameters.AddRange(inputParams);
}
cmd.Parameters.Add(new OracleParameter("resultset", OracleDbType.RefCursor, ParameterDirection.Output));
DataSet ds = new DataSet();
.
.
.
存储过程:
CREATE OR REPLACE PROCEDURE BERT."SP_BIA_OBLIGATION_GROUPED" (
p_bfy in varchar2,
p_fy in varchar2,
p_fm in varchar2,
p_appropriation in varchar2,
p_fund in varchar2,
p_fund_center in varchar2,
p_func_area in varchar2,
p_program in varchar2,
p_boc in varchar2,
p_from_inception in char,
p_red_only in char,
resultset out sys_refcursor
)
AS
BEGIN
OPEN resultset FOR
select decode(grouping(t.description), 1, 'TOTAL', t.description) as description,
case when p_from_inception = '0' then sum(t.amount_cfy) else sum(t.amount_inc) end as amount
from mv_bia_obligation_grouped t
.
.
.
group by grouping sets ((), (t.description))
HAVING count(*) != 0;
存储过程执行并返回所需的结果,但从vb.net调用时不提供数据。在单步执行代码时,我检查了那些正确的参数值,当我检查数据集时,它只有标题没有数据。有没有人知道这里发生了什么?
提前致谢。
答案 0 :(得分:0)
你的代码肯定是C#而不是vb.net,但这里是一个vb.net函数,它返回一个数据集,用于调用存储过程。我使用Oracle客户端(Oracle.DataAccess.Client):
'I always provide a open connection to my functions, this way I can execute many procedures on one connection
Public Function fetch(ByVal oraConnection As OracleConnection, ByVal SomeParameter As String) As DataSet
Dim myCommand As New OracleCommand
Dim DS As New DataSet
Try
With myCommand
.Connection = oraConnection
.CommandText = "Bert.SP_BIA_OBLIGATION_GROUPED"
.CommandType = CommandType.StoredProcedure
.Parameters.Clear()
' Add all your input parameters here ...
.Parameters.Add(New OracleParameter("SomeParameter", OracleDbType.Varchar2, SomeParameter.Length)).Value = SomeParameter
' This is the resultset output parameter
.Parameters.Add(New OracleParameter("pDataOut", OracleDbType.RefCursor))
' I always give my parameters direction just for clarity and readability, no other reason as the default is input
.Parameters(0).Direction = ParameterDirection.Input
.Parameters(1).Direction = ParameterDirection.Output
Dim DA As New OracleDataAdapter(myCommand)
DA.Fill(DS, "DATA")
fetch = DS
End With
Catch exc As Exception
Throw New Exception("Error occurred while retrieving data, the error is: " & exc.Message)
End Try
myCommand = Nothing
End Function
C#代码
public DataSet fetch(OracleConnection oraConnection, string SomeParameter)
{
OracleCommand myCommand = new OracleCommand();
DataSet DS = new DataSet();
try
{
{
var withBlock = myCommand;
withBlock.Connection = oraConnection;
withBlock.CommandText = "Bert.SP_BIA_OBLIGATION_GROUPED";
withBlock.CommandType = CommandType.StoredProcedure;
withBlock.Parameters.Clear();
// Add all your input parameters here ...
withBlock.Parameters.Add(new OracleParameter("SomeParameter", OracleDbType.Varchar2, SomeParameter.Length)).Value = SomeParameter;
// This is the resultset output parameter
withBlock.Parameters.Add(new OracleParameter("pDataOut", OracleDbType.RefCursor));
// I always give my parameters direction just for clarity and readability, no other reason as the default is input
withBlock.Parameters(0).Direction = ParameterDirection.Input;
withBlock.Parameters(1).Direction = ParameterDirection.Output;
OracleDataAdapter DA = new OracleDataAdapter(myCommand);
DA.Fill(DS, "DATA");
fetch = DS;
}
}
catch (Exception exc)
{
throw new Exception("Error occurred while retrieving data, the error is: " + exc.Message);
}
myCommand = null/* TODO Change to default(_) if this is not a reference type */;
}