I have a table which contains a two column(start_time and end_time).I am getting the information of start and end time from the user and adding it to the table.Once the user enters the next start and end time I have to compare it with the database.
Suppose in table one row has start time as 2011-08-10 16:00:00 and end time is 2011-08-10 16:30:00.
Suppose the user enter value 2011-08-10 16:05:00.000 (start_time) and 2011-08-10 16:25:00 (end_time) I am able to capture the by using
String getConflictTimeInBetween = string.Format("select question_id,question_text from " + data_variables.RES_TXT_STRING_QUESTION_TABLE + " where start_time<='{0}' and end_time>='{1}'", start_full, end_full);//question_text='DFS'"2011-06-23 14:55);//
com = new SqlCommand(getConflictTimeInBetween, myConnection);
dr = com.ExecuteReader();
if (dr.HasRows)
{
while (dr.Read())
{
//Assign to your textbox here
conflictQuestionIdAtBetween = dr["question_id"].ToString();
conflictQuestionTextAtBetween=dr["question_text"].ToString();
}
}
Here are some sample overlaps that I want to prevent
-
start_time from
2011-08-10 15:55:00and end_time2011-08-10 16:05:00(five minutes overlap with already existing data) -
start_time from
2011-08-10 16:25:00and end_time2011-08-10 17:00:00(five minutes overlap with already existing data) -
start_time from
2011-08-10 15:00:00and end_time2011-08-10 17:00:00(30 minutes overlap with already existing data)
Can anyone help me how to solve these three issues.
Since you seem to have the SQL part, here’s the algorithm that finds the overlap in ticks between the input time and the row time.