I have got an issue with cast object. I tried to resolve it for a couple of hours. It has to do with data type - raw in Oracle and byte in C#. They seem not compatible.
Function in Oracle
function dupCheck(i_vendor varchar2,i_transactionnumber varchar2) return raw
is
transactionId raw(16);
BEGIN
select id into transactionId from (select tx.id,row_number() over (order by tx.trans_time asc) as seqnum
from test_tx_log tx
where tx.transactionnumber = i_transactionnumber and lower(tx.vendor) = lower(i_vendor)) tx where seqnum = 1;
return transactionId;
exception
when no_data_found then
return transactionId;
END;
C#
using (DbCommand command = connection.CreateCommand())
{
command.CommandType = CommandType.StoredProcedure;
command.CommandText = "mca_test_package.dupCheck";
command.AddParameter("i_vendor", DbType.String, tx.Vendor);
command.AddParameter("i_transactionnumber", DbType.String, tx.TransactionNumber.Trim());
command.AddParameter("transactionId", DbType.Byte, DBNull.Value, ParameterDirection.ReturnValue,16);
command.ExecuteNonQuery();
var txId = new Guid((byte[])command.Parameters["transactionId"].Value);
byte[] buffer = new byte[16];
Guid id = new Guid(buffer);
bool result = (id == txId);
if (result)
{
tx.status = "Success";
Console.WriteLine("No Duplicate {0}", tx);
}
else
{
Console.WriteLine("Duplicate {0}", tx);
tx.status = "RejectedDuplicate";
}
Get the error
Note : My assumption is transactionid
is an output parameter.
transactionId
is null .so you need to handle the null value
if(!Convert.IsDBNull(command.Parameters["transactionId"].Value))
{
var txId = new Guid((byte[])command.Parameters["transactionId"].Value);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.