Hi paulrajmca,
I have created a sample which full fill your requirement you need to modify the code according to your need.
C#
protected void Page_Load(object sender, EventArgs e)
{
DataTable dtDatabase = new DataTable();
dtDatabase.Columns.AddRange(new DataColumn[] { new DataColumn("EmployeeId", typeof(string)), new DataColumn("Date", typeof(DateTime)) });
dtDatabase.Rows.Add("E001", "08/07/2017");
dtDatabase.Rows.Add("E001", "08/08/2017");
dtDatabase.Rows.Add("E001", "08/11/2017");
if (dtDatabase.Rows.Count > 1)
{
DateTime endDate = Convert.ToDateTime(dtDatabase.Rows[dtDatabase.Rows.Count - 1]["Date"]);
string employeeId = Convert.ToString(dtDatabase.Rows[dtDatabase.Rows.Count - 1]["EmployeeId"]);
dtDatabase.Rows.RemoveAt(dtDatabase.Rows.Count - 1);
dtDatabase.AcceptChanges();
DateTime startDate = Convert.ToDateTime(dtDatabase.Rows[dtDatabase.Rows.Count - 1]["Date"]);
int diff = endDate.Subtract(startDate).Days;
if (diff > 1)
{
for (int i = 1; i < diff; i++)
{
dtDatabase.Rows.Add(employeeId, startDate.AddDays(i));
dtDatabase.AcceptChanges();
}
}
dtDatabase.Rows.Add(employeeId, endDate);
dtDatabase.AcceptChanges();
}
}
VB.Net
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
Dim dtDatabase As New DataTable()
dtDatabase.Columns.AddRange(New DataColumn() {New DataColumn("EmployeeId", GetType(String)), New DataColumn("Date", GetType(DateTime))})
dtDatabase.Rows.Add("E001", "08/07/2017")
dtDatabase.Rows.Add("E001", "08/08/2017")
dtDatabase.Rows.Add("E001", "08/11/2017")
If dtDatabase.Rows.Count > 1 Then
Dim endDate As DateTime = Convert.ToDateTime(dtDatabase.Rows(dtDatabase.Rows.Count - 1)("Date"))
Dim employeeId As String = Convert.ToString(dtDatabase.Rows(dtDatabase.Rows.Count - 1)("EmployeeId"))
dtDatabase.Rows.RemoveAt(dtDatabase.Rows.Count - 1)
dtDatabase.AcceptChanges()
Dim startDate As DateTime = Convert.ToDateTime(dtDatabase.Rows(dtDatabase.Rows.Count - 1)("Date"))
Dim diff As Integer = endDate.Subtract(startDate).Days
If diff > 1 Then
For i As Integer = 1 To diff - 1
dtDatabase.Rows.Add(employeeId, startDate.AddDays(i))
dtDatabase.AcceptChanges()
Next
End If
dtDatabase.Rows.Add(employeeId, endDate)
dtDatabase.AcceptChanges()
End If
End Sub