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?

Roniu
  • 79
  • 10
  • what is the exception's type, and what does the message say? – Marc Gravell Sep 09 '14 at 11:45
  • ConfigurationError: tmpcore.dll: Unable to cast object of type 'System.DBNull' to type 'System.String'. at.. In my first post the last line of code is throwing the Exception – Roniu Sep 09 '14 at 11:47

1 Answers1

0

It looks like you're simply getting a null back from the database, which isn't entirely unexpected (no_ata_found, etc)

Just check for that; one way (of several) is:

string xmlValue = sqlCmdSelectReports.Parameters["@xmldata"].Value as string;
Marc Gravell
  • 1,026,079
  • 266
  • 2,566
  • 2,900