I have a table for the hours a business is opened called Schedule with four columns: Id, Working, Commencing, and Finishing.
Monday 1/1/1900 8:00:00 AM 1/1/1900 5:00:00 PM
Tuesday 1/1/1900 8:00:00 AM 1/1/1900 5:00:00 PM
Wednesday 1/1/1900 8:00:00 AM 1/1/1900 5:00:00 PM
Thursday 1/1/1900 8:00:00 AM 1/1/1900 5:00:00 PM
Friday 1/1/1900 8:00:00 AM 1/1/1900 3:00:00 PM
Saturday 1/1/1900 12:00:00 AM 1/1/1900 12:00:00 AM
Sunday 1/1/1900 12:00:00 AM 1/1/1900 12:00:00 AM
I used this query to show the hours open in a gridview table and it works fine. I get a table with Monday through Friday showing and the hours open and close.
select * from Schedule where [Commencing] != [Finishing];
I then created a class called Scheduling.
public class Scheduling
{
public int Id { get; set; }
public string Working { get; set; }
public Scheduling(int Id, string Working)
{
this.Id = Id;
this.Working = Working;
}
}
And updated my ConnectionClass as follows:
public static ArrayList GetCloseSchedule(string Id)
{
ArrayList list = new ArrayList();
string query = string.Format("select * from Schedule where [Commencing] = [Finishing]", Id);
try
{
conn.Open();
command.CommandText = query;
SqlDataReader reader = command.ExecuteReader();
while (reader.Read())
{
int id = reader.GetInt32(0);
string Working = reader.GetString(1);
Scheduling schedules = new Scheduling(id, Working);
list.Add(schedules);
}
}
finally
{
conn.Close();
}
return list;
}
And then I have this in my default.aspx.cs file.
str = "select * from Schedule where [Commencing] = [Finishing]";
com = new SqlCommand(str, con);
ArrayList Scheduling = ConnectionClass.GetCloseSchedule(lblMsgO.Text);
foreach (Scheduling schedules in Scheduling)
{
sb.Append(string.Format(@"{0}<br />",
schedules.Working));
lblMsgO.Text = sb.ToString();
sb.Clear();
reader.Close();
con.Close();
}
It is a very simple query and I have successfully completed several of them so I am not sure why this one is not working. It shows only Sunday and is skipping Saturday even though both rows appear when I test the SQL query in the database.