c# datareader cheking for a null throwing an exception

i have the below code  but when it hits a blank fied it throws up an exception, how do i test for the empty field so that it does not throw up an exception
if (DbReader.GetString(i) == null)

 for (int i = 0; i < fCount; i++)
                {
                    // VERIFY THE DATA IS CORRECT AND VALID INFO
                    // FIND THE crmentity_seq no
                    try
                    {
                        // CYCLE THROUGH THE RECORD SET
                        if (DbReader.GetString(i) == null)   >>>>>>>>>>this still throws up an exception
                        {
                        }
                        else
                        {
                            col = DbReader.GetString(i);
                        }
                   
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("cannot access crmentity finding last number used");
                        // IF NO VALUE DO NOTHING AND LET IT GLOSS OVER
                    }


private OdbcDataReader AccessDB(string sql, string ODBCDB)
        {
            OdbcConnection DbConnection = new OdbcConnection("DSN=" + ODBCDB);
            //  Now open that OdbcConnection object:
         //  sql = "SELECT company FROM alldata1";
     //       sql = "SELECT  account_no  FROM vtiger_account";
            DbConnection.Open();
            // Now using the OdbcConnection, we will create an OdbcCommand:
            OdbcCommand DbCommand = DbConnection.CreateCommand();
            // Using that command, we can issue a Query and create an OdbcDataReader:
            DbCommand.CommandText = sql; //WHERE ((vtiger_account.prosch)='" + BusinessType + "') and ((contactlinkedin.done)=0)";
            OdbcDataReader DbReader = DbCommand.ExecuteReader();

            int fCount = DbReader.FieldCount;
            Console.Write(":");
            for (int i = 0; i < fCount; i++)
            {
                String fName = DbReader.GetName(i);
                //      String wName = DbReader.GetString(i);
                Console.Write(fName + ":");
            }
            String col = "";
            int NewLasNum = 0;
            string[] recinfo; // ARRAY TO HOLD THE REC INFO FOR POSTING OFF
            while (DbReader.Read())
            {
                Console.Write(":");
                recinfo = new string[fCount];  // numbers is a fCount-element array
                for (int i = 0; i < fCount; i++)
                {
                    // VERIFY THE DATA IS CORRECT AND VALID INFO
                    // FIND THE crmentity_seq no
                    try
                    {
                        // CYCLE THROUGH THE RECORD SET
                        if (DbReader.GetString(i) == null)
                        {
                        }
                        else
                        {
                            col = DbReader.GetString(i);
                        }
                   
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("cannot access crmentity finding last number used");
                        // IF NO VALUE DO NOTHING AND LET IT GLOSS OVER
                    }
                    Console.Write(col + ":");
                }
            }
sydneyguyAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Dale BurrellDirectorCommented:
Try using the MSDN reference: http://msdn.microsoft.com/en-us/library/system.data.odbc.odbcdatareader.aspx

DbReader.IsDBNull(i);
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
databoksCommented:
try:


 try
                    {
                        // CYCLE THROUGH THE RECORD SET
                        if (string.IsNullOrEmpty(DbReader.GetString(i)) == null)   >>>>>>>>>>this still throws up an exception
                        {
                        }
                        else
                        {
                            col = DbReader.GetString(i);
                        }
                   
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("cannot access crmentity finding last number used");
                        // IF NO VALUE DO NOTHING AND LET IT GLOSS OVER
                    }
0
sydneyguyAuthor Commented:
thanks for the help found the MSDN very helpful and the extra code picked up something that i ad not thought of

also posted another question re open connections that i thought you may be right up your ally as well.
thanks for the help as always you guys are the best

http://www.experts-exchange.com/Programming/Languages/C_Sharp/Q_27500026.html
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.