榮登10個不同行的次序我有一個DataTable中有記錄這樣的...如何通過日期
JID Date RecentChatString
-----------------------------------------------------------------------
[email protected] 11/Nov/2013 11:53:00 Hi
[email protected] 11/Nov/2013 11:53:10 Hello
[email protected] 11/Nov/2013 11:54:00 Good Morning
[email protected] 11/Nov/2013 12:03:00 Ok
[email protected] 11/Nov/2013 12:05:10 Please reply
[email protected] 11/Nov/2013 12:15:00 Good after noon
[email protected] 11/Nov/2013 12:15:50 Ok bye
我想按日期排序,前10個不重複的記錄,意味着只有最近的聊天每個JID ..
JID Date RecentChatString
-----------------------------------------------------------------------
[email protected] 11/Nov/2013 12:05:10 Please reply
[email protected] 11/Nov/2013 12:15:50 Ok bye
現在我有這樣的代碼。我可以使用此代碼獲取按日期排序的前10條記錄。 但是,它包含重複JID's
。請幫幫我。 (recent_index是一個DataTable)
DataRow recent_dr = recent_index.NewRow();
recent_dr["JID"] = RosterId;
recent_dr["Date"] = DateTime.Now;
recent_dr["RecentChatString"] = _chatline;
recent_index.Rows.Add(recent_dr);
DataTable dtt = new DataTable("RecentChats");
dtt.Columns.Add("JID", Type.GetType("System.String"));
dtt.Columns.Add("Date", Type.GetType("System.DateTime"));
dtt.Columns.Add("RecentChatString", Type.GetType("System.String"));
IEnumerable<DataRow> recentTen = recent_index.AsEnumerable().OrderByDescending(x=>x["Date"]).Take(10);
recentTen.CopyToDataTable(dtt, LoadOption.OverwriteChanges);
dtt.WriteXml(s + "\\FPhoneData\\chats\\index.xml");
什麼是數據庫引擎? –
你嘗試過'.Distinct'嗎? –
@MichaelPerrenoud XML ... –