Let's say I have a DataTable:
DataTable dt = new DataTable();
dt.Columns.Add(new DataColumn("Country", typeof(string)));
dt.Columns.Add(new DataColumn("State", typeof(string)));
Now I populate it
DataRow dn = dt.NewRow();
dn["Country"] = "1";
dn["State"] == "2";
// Add it
dt.Rows.Add(dn);
That works fine. Now if Country and State are zero, I don't want it to add to the table. For example:
dn["Country"] = "0";
dn["State"] = "0";
if (dn["Country"].ToString() != "0" &&
dn["State"].ToString() != "0")
dt.Rows.Add(dn);
That doesn't work. What am I doing wrong there? I've tried setting type to int and that didn't help much either...
Thanks, Jim
Update:
This is more like what I'm doing:
dn["Country"] = (from c in db.Country where c.Zone == 3 select c.Code).Count();
Now if that were to return Zero, the row should not be added to the DataTable. What instead happens is that if the count is greater than 0, its not added either.
Update 2
Got it to work with Any() for now, as suggested by Jon Skeet below. Thanks everyone!