我想编写一个函数"getCount"来为数据表中的不同用户名返回int的结果,如下所示:
static void Main(string[] args)
{
DataTable table = new DataTable();
table.Columns.Add("username", typeof(string));
table.Columns.Add("count", typeof(int));
table.Columns.Add("code", typeof(string));
table.Rows.Add("Peter", 300, "wer");
table.Rows.Add("Peter", 299, "sdf");
table.Rows.Add("Peter", 298, "34d");
table.Rows.Add("Peter", 297, "4ed");
table.Rows.Add("Paul", 200, "1vc");
table.Rows.Add("Paul", 200, "64f");
table.Rows.Add("Paul", 200, "45d");
table.Rows.Add("Paul", 200, "dcd");
//expectedly 300, i.e. the first row of count column for peter
int x1 = getCount(table, "Peter");
//expectedly 200, i.e. the first row of count column for paul
int x2 = getCount(table, "Paul");
}
static int getCount(DataTable dt, string name) …
Run Code Online (Sandbox Code Playgroud) 我有一个带有动态列列的数据表,并希望聚合基于数字的列并将最终行保存到新的数据表中.
DataTable示例: -
PartnerName CreditCol DebitCol AmountCol ....
P1 10 20 30
P2 1 2 3
P3 3 1 10
P2 1 100 200
Run Code Online (Sandbox Code Playgroud)
所需的输出应为: -
PartnerName CreditCol DebitCol AmountCol ....
P1 10 20 30
P2 2 102 203
P3 3 1 10
Run Code Online (Sandbox Code Playgroud)
这里的主要内容是列集,并且是动态的.有时,可能有两列,有时可能是20列.请建议linq查询或任何其他解决方案.
我有一个简单的数据表,有四列和一些数据行:
DataTable results = new DataTable();
results.Columns.Add("Wellbore", typeof(string));
results.Columns.Add("Date", typeof(DateTime));
results.Columns.Add("WB", typeof(string));
results.Columns.Add("factor", typeof(double));
Run Code Online (Sandbox Code Playgroud)
当"date = 1/1/2017"时,我使用Linq查询获取"数据行列表":
var AllRowsAtPlanningDate = results.AsEnumerable()
.Where(x => ((x.Field<DateTime>("Date") == PlanningDate))).ToList();
Run Code Online (Sandbox Code Playgroud)
我想在" "列中获得"不同"值.我只想要而不是再次.wellbore
AllRowsAtPlanningDate
List<string>
list<datarows>
怎么做?我一直在检查一些例子,但无济于事.
我有一个像这样的数据表
ProductId CountThisWeek CountLastWeek
1 10 15
1 20 5
2 5 10
2 10 15
2 10 20
3 10 15
Run Code Online (Sandbox Code Playgroud)
我需要通过“压缩”(按 productId 求和)我的初始数据表来获得一个新的数据表,如下所示:
ProductId CountThisWeek CountLastWeek
1 30 20
2 25 45
3 10 15
Run Code Online (Sandbox Code Playgroud)
有没有办法使用 LINQ 或其他技术来做到这一点(.NET 3.5)?
I have a c# code as below, Its showing error at IEnumerable<\u003C\u003Ef__AnonymousType0
Can someone tell me how to solve it.
dataSet = this.GetData.getInfo("SELECT b.nBatchID, td.F_Name &' '& td.M_Name &' '& td.L_Name AS StaffName, b.BatchName FROM (Batch AS b LEFT JOIN BatchTrainer AS bt ON b.nBatchID = bt.nBatchId) LEFT JOIN TrainerDetails AS td ON bt.TrainerId = td.TrainerID", "Batch");
IEnumerable<\u003C\u003Ef__AnonymousType0<object, string, string>> datas = dataSet.Tables[0].Copy().AsEnumerable().GroupBy<DataRow, object>((Func<DataRow, object>) (row => row["nBatchId"])).Select(g =>
{
var data = new{ id = g.Key, text = string.Join(",", …
Run Code Online (Sandbox Code Playgroud)