0

This is the SQL Function:

create or replace FUNCTION "TEMPXML"
(
 ID IN NUMBER
)
RETURN CLOB IS
val CLOB;
BEGIN
 val:=null;
 BEGIN
  SELECT TEMPID INTO val FROM TEMPDATA WHERE TempdataID=I;
  exception
  when no_data_found then
   null;
 end;
return val;
END TEMPXML;

In C# I am using Parameter.ReturnValue but the value returned is always DBNull and I get an Exception Unable to cast object of type 'System.DBNull' to type 'System.String'

sqlCmdSelectReports.Parameters.Add(new OleDbParameter("@xmldata", OleDbType.LongVarChar)).Direction = ParameterDirection.ReturnValue;
sqlCmdSelectReports.ExecuteNonQuery();
String xmlValue = (String)sqlCmdSelectReports.Parameters["@xmldata"].Value;

The last line throws an Exception. Do I use a wrong code in C# or the SQL Function is wrong coded?

4

1 回答 1

0

看起来您只是从数据库中返回一个空值,这并非完全出乎意料(no_ata_found等)

只需检查一下;一种(几种)方法是:

string xmlValue = sqlCmdSelectReports.Parameters["@xmldata"].Value as string;
于 2014-09-09T11:50:48.107 回答