Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 205
  • Last Modified:

Detrmining if a colum exsits in a dataset



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)
                  {
                        dsPayCheck.Tables["PayCheckComponents"].Columns.Add(dc);
                  }

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?

Thanks,
Justin
0
jlazanowski
Asked:
jlazanowski
  • 2
  • 2
1 Solution
 
rajaloysiousCommented:
it should be

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

i have assumed that the column name is "key"

cheers
0
 
jlazanowskiAuthor Commented:
if (dsPayCheck.Tables["PayCheckAdjustments"].Columns.IndexOf("key") <0)

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

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

should work
0
 
jlazanowskiAuthor Commented:
Jeez... helps to check your code huh. Ok it works thanks for the help

Justin
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now