Does field exist???

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)
 
E

Eliyahu Goldin

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
 
W

William F. Robertson, Jr.

You can also check the column .Value to DBNull.

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

bill
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,043
Latest member
CannalabsCBDReview

Latest Threads

Top