Link to home
Start Free TrialLog in
Avatar of Natavia Finnie
Natavia FinnieFlag for United States of America

asked on

Oracle Datareader null check extention method

Can we create a extension method ToVauleOrDefault on the DataReader, so when we do reader.GetValue(ordinalId).ToValueOrDefault<string>, within that method it will check null and then convert using oracle datereader

public static T ValueOrDefault<T>(this XElement element, T defaultValue = default(T))
        {
            if (element == null)
            {
                return defaultValue;
            }

            return element.Value.To(defaultValue);
        }

Open in new window

SOLUTION
Avatar of kaufmed
kaufmed
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Natavia Finnie

ASKER

@kaufmed

string x = reader.ValueOrDefault("FIRST_NAME", "N/A");

Gives an error under 'reader' : cannot convert instance argument type 'Oracle.DataAccess.Client.OracleDataReader' to 'System.Data.OracleClient.OracleDataReader'
It sounds like you're mixing two version of the Oracle stuff. Back in the day, when Microsoft released .NET they included their own classes to connect with Oracle. Oracle a few years later released their own .NET libraries, and those libraries became favored. (And many years later Oracle released a fully-manged .NET client that you could pull in solely from NuGet.) Microsoft subsequently deprecated the Oracle classes. The classes that are in System.Data.OracleClient are the Microsoft classes. Don't use those. Just use the classes from Oracle.DataAccess.Client...those are the Oracle-written classes.
Do you have the Oracle client installed on your machine? If no, then I would suggest importing the managed driver from NuGet--it's much easier to work with from an installation perspective.

User generated image
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial