Note: your data are stored in wrong way...
I'd suggest to join data in col1 with col2 based on time column. Take a look at below code:
DataTable dt = new DataTable();
dt.Columns.AddRange(new DataColumn[]
{
new DataColumn("Time", typeof(string)),
new DataColumn("Col1", typeof(int)),
new DataColumn("Col2", typeof(int))
});
dt.Rows.Add(new object[]{"10:00", 1, null});
dt.Rows.Add(new object[]{"11:00", 2, null});
dt.Rows.Add(new object[]{"10:00", null, 3});
dt.Rows.Add(new object[]{"11:00", null, 4});
var c1 = dt.AsEnumerable()
.Where(x => !DBNull.Value.Equals(x["Col1"]))
.Select(x=> new {Time = x.Field<string>("Time"), Col1 = x.Field<int>("Col1")})
.ToList();
var c2 = dt.AsEnumerable()
.Where(x => !DBNull.Value.Equals(x["Col2"]))
.Select(x=> new {Time = x.Field<string>("Time"), Col2 = x.Field<int>("Col2")})
.ToList();
var result = (from cc1 in c1
join cc2 in c2 on cc1.Time equals cc2.Time
select new { cc1.Time, cc1.Col1, cc2.Col2})
.ToList();
Result:
Time Col1 Col2
10:00 1 3
11:00 2 4
If you would like to get result as a datatable object, use
CopyToDataTable
method.
See:
DataTableExtensions.CopyToDataTable Method (System.Data) | Microsoft Learn[
^]