I have 2 DataTables formed by 2 complex queries, the results of which I want to merge and bind to datagridview, in C# code. i did not want to do any joins again of the 2 sqls since its already complex, and I use dynamic sql for this in C# code. (sql server compact - SPs not possible).
the code I used:
dataT = FkDataAccess.GetDataPostsCars(selTmpMPs,fromDateTime, toDateTime);
dataTLocationsTransposed = FkDataAccess.GetLocationDetailsTransposed();
dataTMerged = dataTLocationsTransposed.Copy();
dataTMerged.Merge(dataT);
this.dataGridView1.DataSource = dataTMerged;
dataT result has columns with some data:
<<== marked is the expected row from dataTLocationsTransposed to be merged to dataT
MonitorDateTime MainGate SouthAdminBuilding WestGate
Main-Date det.. South side of admin…west-gate det…<<==
01.02.2014 13:00 6 5 3 <-dataT
21.02.2014 14:00 45 6 8 <-dataT
dataTLocationsTransposed obtains details of the above columns and i tested with 2 queries, Q1 and Q2. Q1 works, added as a new row in the dataT column struct, but it creates 4 other columns names Column1, etc.. in addition to the one shown above.. I need the results just below the dataT column struct.
Q1:
SELECT '',
MAX(CASE WHEN LocColumn = 'MainGate' THEN LocDescription ELSE '' END),
MAX(CASE WHEN LocColumn = 'SouthAdminBuilding' THEN LocDescription ELSE '' END),
MAX(CASE WHEN LocColumn = 'WestGate' THEN LocDescription ELSE '' END)
FROM MonitorLocationDetails
WHERE LocColumn IN ('MainGate','SouthAdminBuilding','WestGate')
this produces results like :
col1 col2 col3 col4 MonitorDateTime MainGate SouthAdminBuilding WestGate
expected what i want is without the col1, col2..... but just underneath the specified column names.
So when i modify Q1 to Q2 which also yields result, but it fails at the Merge call from C#.
Q2:
SELECT '' AS MonitorDateTime,
MAX(CASE WHEN LocColumn = 'MainGate' THEN LocDescription ELSE '' END)
AS MainGate,
MAX(CASE WHEN LocColumn = 'SouthAdminBuilding' THEN LocDescription
ELSE '' END) AS SouthAdminBuilding,
MAX(CASE WHEN LocColumn = 'WestGate' THEN LocDescription ELSE '' END)
AS WestGate
FROM MonitorLocationDetails
WHERE LocColumn IN ('MainGate','SouthAdminBuilding','WestGate')
query for the other merged datatable dataT is:
SELECT T.MonitorDateTime,T.MainGate,T.SouthAdminBuilding,T.WestGate
FROM GdRateTempPosts T WHERE T.MonitorDateTime BETWEEN @fromDateTime
AND @toDateTime ORDER BY T.MonitorDateTime
any help much appreciated. Thank you.