1) You need to pass the both date in proper format so you can compare it as it takes is in MM-dd-YYYY format.
Check the below sample code and implement it as per your code logic in your code.
C#
DataTable dt = new DataTable();
dt.Columns.AddRange(new DataColumn[2] { new DataColumn("SId",typeof(int))
,new DataColumn("RDate",typeof(string))});
DateTime date1 = Convert.ToDateTime("02-01-2018");
DateTime date2 = Convert.ToDateTime("02-03-2018");
if (date1 > date2)
{
//MessageBox("Please Enter a Valid Date Range");
}
else
{
int datediff = date2.Subtract(date1).Days + 1;
for (int i = 1; i <= datediff; i++)
{
for (int j = 0; j < datediff; j++)
{
dt.Rows.Add(i, date1.AddDays(j));
}
}
}
VB.Net
Dim dt As DataTable = New DataTable()
dt.Columns.AddRange(New DataColumn(1) {New DataColumn("SId", GetType(Integer)), New DataColumn("RDate", GetType(String))})
Dim date1 As Date = Convert.ToDateTime("02-01-2018")
Dim date2 As Date = Convert.ToDateTime("02-03-2018")
If date1 > date2 Then
' Your Message box code
' MsgBox("Please Enter a Valid Date Range")
Else
Dim datediff As Integer = date2.Subtract(date1).Days + 1
For i As Integer = 1 To datediff
For j As Integer = 0 To datediff - 1
dt.Rows.Add(i, date1.AddDays(j))
Next
Next
End If