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
VulpesPosted Jun 25, 2013, 5:42 AM
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
nishant ranjanPosted Jun 25, 2013, 6:13 AM
nishant ranjanPosted Jun 25, 2013, 5:13 AM
cannot implicitly convert type system.collections.generic.ienumerable
VulpesPosted Jun 25, 2013, 5:07 AM
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 ranjanPosted Jun 25, 2013, 5:01 AM
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
VulpesPosted Jun 25, 2013, 4:47 AM
where dr["eid"].ToString() == "113"
nishant ranjanPosted Jun 25, 2013, 4:12 AM
nishant ranjanPosted Jun 25, 2013, 4:08 AM
Jignesh TrivediPosted Jun 25, 2013, 4:06 AM
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.
VulpesPosted Jun 25, 2013, 4:02 AM
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.
nishant ranjanPosted Jun 25, 2013, 3:48 AM
Sanjeeb LenkaPosted Jun 25, 2013, 12:36 AM
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
Jignesh TrivediPosted Jun 24, 2013, 11:12 PM
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.
Amit ChoudharyPosted Jun 24, 2013, 8:41 AM
VulpesPosted Jun 24, 2013, 8:35 AM
using System.Linq;
// ....