2011-12-20 54 views
1

來的DataTable我有2個確定年代,一個像:合併不同數量的條目

 
Date   %change_1 
6/20/2011 0.112 
6/21/2011 0.2365 
6/22/2011 -0.248 
6/23/2011 -0.965 
6/24/2011 0.123 
6/27/2011 0.6544 
6/28/2011 -0.789 

的另外一個名字:

 
Date   %change_2 
6/20/2011 -0.45 
6/22/2011 -0.6 
6/23/2011 0.98 
6/27/2011 -0.845 

我想爲了只需要合併這個數據像日期一米欄:

 
Date   %change_1 %change_2 
6/20/2011 0.112  -0.45 
6/22/2011 -0.248  -0.6 
6/23/2011 -0.965  0.98 
6/27/2011 -0.6544  -0.845 

我不想在我的數據的任何變化(我有,如果我只是它們合併)

這裏是我的代碼

 //cherche les last price 
     DataTable TickerPrice = new DataTable("Data"); 
     TickerPrice = CheckBloomi(TickerName + " equity", "CHG_PCT_1D", FromThisTime, ToThisTime); 

     //cherche les price indexprice 
     DataTable IndexPrice = new DataTable("Data"); 
     IndexPrice = CheckBloomi(Bchmrk, "CHG_PCT_1D", FromThisTime, ToThisTime); 

     DataSet MarketData = new DataSet(); 
     MarketData.Merge(TickerPrice); 
     MarketData.Merge(IndexPrice); 

     DataTable Recap = MarketData.Tables.Add("Recap"); 

感謝

+0

和哪裏是你的代碼不能夠做到這一點? – 2011-12-20 08:31:33

+0

「不希望我的數據有任何變化」是什麼意思? – 2011-12-20 08:38:07

+0

這意味着我不想要數據正確合併,例如我會有行:2011年6月22日0.2365 -0.6根據我的示例 – 2011-12-20 09:07:18

回答

0

你需要在關係代數類似的半連接,在SQL它會是這個樣子:

Select * from Datatable1 D1 
where exists 
( 
    Select * from Datatable D2 where D1.Date = D2.Date 
) 

此外,你應該提供你的代碼不起作用

+1

此SQL將選擇D1中的日期在D2中相同的字段。簡單的連接日期應該做的技巧'選擇日期,change_1,change_2從table1連接table2在table1.date = table2.date' – Reniuz 2011-12-20 09:01:20