Detrmining if a colum exsits in a dataset

Posted on 2005-04-08
Last Modified: 2010-04-16

I have a column that I add to an exisiting dataset. I want to add this column the first time it loops through this code, but ignore the column add on subsequent trips through the loop.

Currently I have the following code
if (dsPayCheck.Tables["PayCheckComponents"].Columns["key"] == null)

This stops the unhandled exception if the column does not exsit the first time, but it still steps into the if statement if it's a return trip to the loop.

What am I doing wrong?

Question by:jlazanowski
    LVL 8

    Accepted Solution

    it should be

    if (dsPayCheck.Tables["PayCheckComponents"].Columns.IndexOf("key") <0 )

    i have assumed that the column name is "key"

    LVL 1

    Author Comment

    if (dsPayCheck.Tables["PayCheckAdjustments"].Columns.IndexOf("key") <0)

    Is not working, it still steps into the if statement.

    LVL 8

    Expert Comment

    That means the column name of the variable dc is not "key"
    if (dsPayCheck.Tables["PayCheckComponents"].Columns.IndexOf(dc.ColumnName) <0 )

    should work
    LVL 1

    Author Comment

    Jeez... helps to check your code huh. Ok it works thanks for the help


    Featured Post

    Do You Know the 4 Main Threat Actor Types?

    Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

    Join & Write a Comment

    Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
    It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now