数据表选择行数c#WFA

时间:2018-07-23 20:54:35

标签: c# sql count distinct

帮助我获取行上每个数据的数量

我尝试使用查询SELECT * FROM TABLEthis 我尝试区分并添加this之类的coloum, 代码:

clsAccess db = new clsAccess(PATH);
        string query = "";
        query = "SELECT DISTINCT KODE, JUDUL FROM VW_PEMINJAMAN ORDER BY JUDUL ASC";
        DataTable dt = new DataTable();
        dt = db.GetSummaryData(query);

        dt.Columns.Add("JUMLAH", typeof(int));
        dt.Columns["JUMLAH"].SetOrdinal(2);

        for (int i = 0; i < dt.Rows.Count; i++)
        {
            string judul = dt.Rows[i]["KODE"].ToString();

            dt.Rows[i]["JUMLAH"] = 0;
        }


        grdAsosiasi.DataSource = dt;
        grdAsosiasi.AutoSizeCols();
        db.CloseDatabaseConnection();here

我如何在JUMLAH coloum的每一行中计数?

SELECT Count(KODE) AS [KODE_BUKU] FROM VW_PEMINJAMAN;

我得到每一行

if (dt.Rows.Count > 0){
string abc = dt.rows[0]["KODE_BUKU"].ToString();

}

但是仅显示1行...我如何才能将所有行计数在数据表中?

1 个答案:

答案 0 :(得分:0)

假设您要根据屏幕截图来获取每个Kode的计数。将您的SQL更改为使用<many-to-one field="author" target-entity="User"> <join-column name="author_id" referenced-column-name="id" nullable="false" /> </many-to-one> 代替GROUP BY

DISTINCT