Avatar of Natavia Finnie
Natavia Finnie
Flag 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

.NET ProgrammingC#

Avatar of undefined
Last Comment
Natavia Finnie

8/22/2022 - Mon
SOLUTION
kaufmed

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
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'
kaufmed

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.
kaufmed

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.

Screenshot
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
ASKER CERTIFIED SOLUTION
Natavia Finnie

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.