使用c#将两个数据集中的特定列合并到第三个数据集的方法

时间:2012-06-20 07:33:34

标签: c# asp.net dataset

假设我有两个Dataset ds1 & ds2来自两个不同Tables

的数据
Sql1 = "Select sTitle, sDate,active,color FROM TABLE1"
Sql2 = "Select eName, eDate FROM TABLE2"

将这两个ds1, ds2合并到第三个数据集ds3中的最佳方法是什么? EventTitle, BlockedDate我想从sTitle, sDate ds1eName, eDate ds2获取;with Calendar as ( select EventID, EventTitle, EventStartDate, EventEndDate, EventEnumDays,EventStartTime, EventRecurring, EventStartDate as PlannedDate ,EventType from EventCalender where EventActive = 1 AND LanguageID =1 AND EventBlockDate = 1 AND( EventStartDate >= GETDATE() OR EventEndDate >= GETDATE() ) union all select EventID, EventTitle, EventStartDate, EventEndDate, EventEnumDays,EventStartTime, EventRecurring, dateadd(dd, 1, PlannedDate) ,EventType from Calendar where (EventRecurring = 1 and dateadd(dd, 1, PlannedDate) <= EventEndDate ) OR (EventRecurring = 0 and dateadd(dd, 1, PlannedDate) <= EventEndDate) ) select EventID, EventStartDate, EventEndDate, PlannedDate as [EventDates], Cast(PlannedDate As datetime) +''+ Cast(EventStartTime As time) AS DT, EventTitle ,EventType from Calendar where (PlannedDate >= GETDATE()) AND ',' + EventEnumDays + ',' like '%,' + cast(datepart(dw, PlannedDate) as char(1)) + ',%' AND PlannedDate <= DATEADD(month, 2, GETDATE()) or EventEnumDays is null order by EventID, PlannedDate option (maxrecursion 0)

我需要知道一种快速的方法,考虑到每个查询可能最多有200行

实际的sql1是

{{1}}

1 个答案:

答案 0 :(得分:0)

我认为您应该使用query stringjoin加入Union,而不是合并datatable