SqlConnection con = new SqlConnection(strConnString);
con.Open();
SqlDataAdapter sda = new SqlDataAdapter("select availability FROM doc_availabledays where dname='" + Label2.Text + "'", con);
DataSet dss = new DataSet();
sda.Fill(dss, "doc_availabledays");
DataRow drr = dss.Tables[0].Rows[0];
drr["availability"].ToString();
if (!e.Day.IsOtherMonth)
{
foreach (DataRow dr in dss.Tables[0].Rows)
{
if ((dr["availability"].ToString().Equals(DayOfWeek.Monday))||(dr["availability"].ToString().Equals(DayOfWeek.Tuesday))||(dr["availability"].ToString().Equals(DayOfWeek.Wednesday)))
{
e.Cell.BackColor = Color.PaleVioletRed;
}
}
}
Asked
Active
Viewed 43 times
0

DanielBarbarian
- 5,093
- 12
- 35
- 44
-
What help you need? Question isn't clear – Sami Aug 24 '16 at 05:49
1 Answers
0
I think it's better to use the safe casting.
string [] data = { "Monday", "Thursday", "Wednesday", "Tuesday" };
DayOfWeek d;
var dt = DateTime.Now;
foreach (var st in data)
{
if (Enum.TryParse<DayOfWeek>(st, out d) && d == dt.DayOfWeek)
{
string abc = "i M Here";
}
}
It looks like you have multiple columns in the DataTable for DayOfWeek
. If that's the case then use the same condition with multiple OR operators ||
or loop to the DataRow column as well.
For further details, take a look at this: C#: DateTime.DayOfWeek to string comparison

Community
- 1
- 1

Nawaz Khan
- 9
- 2