Does field exist???

  • Thread starter Thread starter DaveF
  • Start date Start date
D

DaveF

Is there anyway to check a dataset to see if a field exists?


foreach(DataRow row in ds.Tables[0].Rows)
{
if(row["fldname1"].ToString() == null) ******************This does not
work???????????????????????
{
cbFields.Items.Add (new ListItem(row["fldname"].ToString(),
row["fldtext"].ToString()));
}
else
{
cbFields.Items.Add (new ListItem(row["fldname"].ToString(),
row["fldtext"].ToString()));
}
}


--


David Fetrow
Helixpoint LLC.
http://www.helixpoint.com
(e-mail address removed)
 
There are two separate questions:
Q1. Does a field exists?
A1. row.Table.Columns.Contains("fldname")

Q2. Is the field value null?
A2. row.IsNull("fldname")

Eliyahu
 
You can also check the column .Value to DBNull.

if ( row["field1"] == DBNull.Value )
//the column is null.

bill
 
Back
Top