ds_update.ReadXml(strOutPath + @"\backup.xml"); //ds_update is dataset
data contained is
eid mid path
112 500 xyz
112 501 abc
113 500 ddd
113 500 aaa
113 600 uuu
what i want is result as
mid
500 3
501 1
600 1
how can i use group by in datatable.select
DataRow[] results = ds_update.Tables[0].Select(?????????);
foreach (DataRow dr in results)
{
}
i want each mid with no of times its occurrence
Loading

VulpesRank #55 · 29.2K reputationPosted Jun 25, 2013, 1:42 AM EDT
To do something like you want to do, I think you'll have to use a 'named' type instead.
If you add this class:
class MidCount
{
public object Mid { get; set; }
public int Count { get; set; }
}
and then change the rest of the code to this, then it should work:
IEnumerable
if (condition)
{
query = from DataRow dr in ds_update.Tables[0].Rows
else
{
where dr["eid"].ToString() == "113" && date == something
VulpesRank #55 · 29.2K reputationPosted Jun 24, 2013, 4:35 AM EDT
using System.Linq;
// ....
Amit ChoudharyRank #145 · 15.8K reputationPosted Jun 24, 2013, 4:41 AM EDT
Jignesh TrivediRank #16 · 50.3K reputationPosted Jun 24, 2013, 7:12 PM EDT
hi,
Please refer http://stackoverflow.com/questions/8472005/efficient-datatable-group-by
it has multiple way to group by with datatable
hope this will help you.
Sanjeeb LenkaRank #301 · 8.3K reputationPosted Jun 24, 2013, 8:36 PM EDT
http://stackoverflow.com/questions/6551447/c-using-linq-to-group-by-multiple-columns-in-a-datatable
http://www.codeproject.com/Articles/28132/Implementing-Simple-SQL-Group-by-Functionality-wit
nishant ranjanRank #4,961 · 317 reputationPosted Jun 24, 2013, 11:48 PM EDT
VulpesRank #55 · 29.2K reputationPosted Jun 25, 2013, 12:02 AM EDT
http://msdn.microsoft.com/en-us/library/system.data.datacolumn.expression.aspx
Although there are some similarities to SQL it's far more limited and AFAICS there are no constructs available which would enable you to do GROUP BY.
Jignesh TrivediRank #16 · 50.3K reputationPosted Jun 25, 2013, 12:06 AM EDT
Hi,
In this case Var is not useful because it is strongly typed. at compile time,the compiler determines the type.
so if you are .net framework 4.0 user than use can use dynamic instead of var.
dynamic query = null;
if(condition)
{
query=...
}
else
{
query=...
}
Please refer
http://msdn.microsoft.com/en-us/library/dd264736.aspx
http://msdn.microsoft.com/en-us/library/vstudio/dd264741.aspx
hope this will help you.
nishant ranjanRank #4,961 · 317 reputationPosted Jun 25, 2013, 12:08 AM EDT
nishant ranjanRank #4,961 · 317 reputationPosted Jun 25, 2013, 12:12 AM EDT
VulpesRank #55 · 29.2K reputationPosted Jun 25, 2013, 12:47 AM EDT
where dr["eid"].ToString() == "113"
nishant ranjanRank #4,961 · 317 reputationPosted Jun 25, 2013, 1:01 AM EDT
var query;
if(condition)
{
query= from datarow dr in ds_update.table[0].rows
where dr["eid"].tostring()=="113"
.......
}
else
{
query=from datarow dr in ds_update.table[0].rows
where dr["eid"].tostring()=="113" and date=something
.......
}
i have to do some thing like this
VulpesRank #55 · 29.2K reputationPosted Jun 25, 2013, 1:07 AM EDT
var query;
try instead:
IEnumerable
However, you'll also need to add:
select dr;
at the end of both your queries for the syntax to be valid.
nishant ranjanRank #4,961 · 317 reputationPosted Jun 25, 2013, 1:13 AM EDT
cannot implicitly convert type system.collections.generic.ienumerable
nishant ranjanRank #4,961 · 317 reputationPosted Jun 25, 2013, 2:13 AM EDT