I am having the following results in a datatable where I would like to validate the records to see if any over lapping exists with the given date from UI
When user tries to edit the first entry by giving a end date >= December 22 I would like to throw a validation saying over lap exists. Here is the sample code I am working out but didn't worked
public partial class Form1 : Form
{
DataTable dt = new DataTable();
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
dt.Columns.Add("Id", typeof(int));
dt.Columns.Add("StartDt", typeof(DateTime));
dt.Columns.Add("EndDt", typeof(DateTime));
dt.Rows.Add(1, new DateTime(2021, 11, 30), new DateTime(2021, 12, 14));
dt.Rows.Add(2, new DateTime(2021, 12, 22), new DateTime(2022, 01, 05));
}
private void button1_Click(object sender, EventArgs e)
{
foreach (DataRow row in dt.Rows)
{
if (Convert.ToDateTime(row["StartDt"]).Date >= dateTimePicker1.Value.Date && Convert.ToDateTime(row["EndDt"]).Date <= dateTimePicker1.Value.Date)
{
}
}
}
}
When I select the date as 22 December 2021 as per the data it falls in 2nd row it should return false
Also any possible solution in linq with out looping data