I have two tables called visits and members and i am getting the data by using following query..
string sql= @"SELECT member_Firstname, member_Lastname, member_Postcode,
visit_DateTime, visit_Status, visit_Logout_DateTime, visits.member_Id, visit_AlertMsg
FROM members, visits
WHERE members.member_Id = visits.member_Id
AND members.member_Active LIKE 'y%'";
at here i am getting the visit_DateTime values with by using some comparisons with combobox values
datatable dt = helper.getdata(sql)
foreach (DataRow row in dt.Rows)
{
if (row["visit_Logout_DateTime"] != null)
{
DateTime dtlogout = DateTime.Parse(row["visit_Logout_DateTime"].ToString());
if (dtlogout != null)
{
if (cbPeriod.Text == "Today")
{
newItem.lblTime.Text = dtlogout.ToString("HH':'mm':'ss");
}
else
newItem.lblTime.Text = dtlogout.ToString("yyyy'-'MM'-'dd' - 'HH':'mm':'ss");
}
}
}
but i got the error at this line DateTime dtlogout = DateTime.Parse(row["visit_Logout_DateTime"].ToString());
error : string was not recognised as valid datetime (because of one value in that row is empty)
the row "visit_Logout_DateTime"
i have got the values of "visit_Logout_DateTime" like this….
firstname lastname postcode visit_Logout_DateTime
------------- -------- --------- ---------------------
rob peter hhd344h
peter chan hy78kjk 2011-09-08 12:09:08
rock sam yudufg3746h 2011-08-08 09:08:45
i have tried that for checking the empty values of this visit_Logout_DateTime like i mentioned above..
but i have failed for chacking ever value is empty or not in that row…
how to check every value in this row (row[“visit_Logout_DateTime”]) is empty or not
would any one pls help me on this guys …
many thanks….
Instead of checking if the column is
null, you should check if the contents of the column arenull. You can do that by comparing it toDBNull.Value: