本文介紹了我怎樣才能得到列“pieces"的總和?在數(shù)據(jù)表中?的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!
問(wèn)題描述
限時(shí)送ChatGPT賬號(hào)..
如何獲得數(shù)據(jù)表中pieces"列的總和?假設(shè)我有下表.如何計(jì)算 article="milk" 和 artno="15" 的總"件數(shù)?
How can I get a sum for the column "pieces" in a datatable? Say I had the following table. How can I calculate the "total" pieces for article="milk" and artno="15"?
Columns: article artno pieces
Rows:
1 milk 15 1
2 water 12 1
3 apple 13 2
4 milk 15 1
5 milk 16 1
6 bread 11 2
7 milk 16 4
我的新數(shù)據(jù)表的結(jié)果應(yīng)該是這樣的:
The Result of the my new DataTable should be this:
Columns: article artno pieces
Rows:
1 bread 11 2
2 water 12 1
3 apple 13 2
4 milk 15 2
5 milk 16 5
我的代碼:
foreach (DataRow foundDataRow in foundRows1)
{
int i = 0;
foreach (DataRow dataRow in foundRows2)
{
if (object.Equals(dataRow.ItemArray[0], foundDataRow.ItemArray[0])
&& object.Equals(dataRow.ItemArray[3], foundDataRow.ItemArray[3]))
{
i = i + Convert.ToInt16(dataRow.ItemArray[4]);
}
}
Debug.Print(i.ToString());
}
抱歉,我是新的數(shù)據(jù)庫(kù)開(kāi)發(fā)人員,我的英語(yǔ)不太好.
Sorry, but i'm new DataBase developer and my english speak language is not so good.
推薦答案
使用 DataTable.Compute
方法,你可以這樣做:
Using the DataTable.Compute
method, you can do:
int sum = (int)table.Compute("Sum(pieces)", "article = 'milk' AND artno='15'");
這篇關(guān)于我怎樣才能得到列“pieces"的總和?在數(shù)據(jù)表中?的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內(nèi)容來(lái)源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問(wèn)題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!