首先,这是一个sql语句,实现的是分类统计售出数量 string strsql = "select TItemStockHistory.itemid,TItem.cname,sum(TItemStockHistory.quantity) as num "
+ "from TItemStockHistory join TItem"
+ " on TItemStockHistory.itemid=TItem.itemid where TItemStockHistory.historytype=5"
+ " group by TItemStockHistory.itemid";
问题是:怎么把sum(TItemStockHistory.quantity) 这个值 填充到 datagirdview 里面去 ??完整代码如下:mds = new MainDataSet();
newArrayList = new ArrayList();
//DataController.adaptItemStockHistory.Fill(mds.TItemStockHistory); string strsql = "select TItemStockHistory.itemid,sum(TItemStockHistory.quantity) as num "
+ "from TItemStockHistory join TItem"
+ " on TItemStockHistory.itemid=TItem.itemid where TItemStockHistory.historytype=5"
+ " group by TItemStockHistory.itemid"; SqlDataAdapter adat = new SqlDataAdapter(strsql, DataController.adaptItemStockHistory.Connection);
adat.Fill(mds.TItemStockHistory);
//da1 = new BIMS.MainDataSetTableAdapters.TItemStockHistoryTableAdapter(strsql,DataController.adaptItemStockHistory.Connection);
//da1.Fill(mds.TItemStockHistory); newView = new DataView(mds.TItemStockHistory);
newArrayList.Clear();
foreach (DataRowView drv in newView)
{
newArrayList.Add((MainDataSet.TItemStockHistoryRow)drv.Row);
}
this.gdvShowSold.Rows.Clear();
for (int i = 0; i < newArrayList.Count; i++)
{
MainDataSet.TItemStockHistoryRow newRow = (MainDataSet.TItemStockHistoryRow)newArrayList[i];
//MainDataSet.TItemRow itemRow=(MainDataSet.TItemRow)newArrayList[i]; this.gdvShowSold.Rows.Add();
this.gdvShowSold.Rows[i].Cells["itemid"].Value =(newRow.IsitemidNull() ? "" : newRow.itemid.ToString());
//this.gdvShowSold.Rows[i].Cells["cname"].Value=(itemRow.IscnameNull() ? "" : itemRow.cname);
this.gdvShowSold.Rows[i].Cells["cname"].Value = "";
this.gdvShowSold.Rows[i].Cells["sumsold"].Value =(newRow.IsquantityNull() ? "" : newRow.quantity.ToString());
}
+ "from TItemStockHistory join TItem"
+ " on TItemStockHistory.itemid=TItem.itemid where TItemStockHistory.historytype=5"
+ " group by TItemStockHistory.itemid";
问题是:怎么把sum(TItemStockHistory.quantity) 这个值 填充到 datagirdview 里面去 ??完整代码如下:mds = new MainDataSet();
newArrayList = new ArrayList();
//DataController.adaptItemStockHistory.Fill(mds.TItemStockHistory); string strsql = "select TItemStockHistory.itemid,sum(TItemStockHistory.quantity) as num "
+ "from TItemStockHistory join TItem"
+ " on TItemStockHistory.itemid=TItem.itemid where TItemStockHistory.historytype=5"
+ " group by TItemStockHistory.itemid"; SqlDataAdapter adat = new SqlDataAdapter(strsql, DataController.adaptItemStockHistory.Connection);
adat.Fill(mds.TItemStockHistory);
//da1 = new BIMS.MainDataSetTableAdapters.TItemStockHistoryTableAdapter(strsql,DataController.adaptItemStockHistory.Connection);
//da1.Fill(mds.TItemStockHistory); newView = new DataView(mds.TItemStockHistory);
newArrayList.Clear();
foreach (DataRowView drv in newView)
{
newArrayList.Add((MainDataSet.TItemStockHistoryRow)drv.Row);
}
this.gdvShowSold.Rows.Clear();
for (int i = 0; i < newArrayList.Count; i++)
{
MainDataSet.TItemStockHistoryRow newRow = (MainDataSet.TItemStockHistoryRow)newArrayList[i];
//MainDataSet.TItemRow itemRow=(MainDataSet.TItemRow)newArrayList[i]; this.gdvShowSold.Rows.Add();
this.gdvShowSold.Rows[i].Cells["itemid"].Value =(newRow.IsitemidNull() ? "" : newRow.itemid.ToString());
//this.gdvShowSold.Rows[i].Cells["cname"].Value=(itemRow.IscnameNull() ? "" : itemRow.cname);
this.gdvShowSold.Rows[i].Cells["cname"].Value = "";
this.gdvShowSold.Rows[i].Cells["sumsold"].Value =(newRow.IsquantityNull() ? "" : newRow.quantity.ToString());
}
sql 语句里面是 AS 成了 num 列,但是 newRow 的时候 . 不出来 这个列明,原始表 是没有这个字段的
this.gdvShowSold.Rows[i].Cells["cname"].Value=(itemRow.IscnameNull() ? "" : itemRow.cname); ???
this.gdvShowSold.Rows[i].Cells["sumsold"].Value = newRow["sumsold"];就是这样实现的 直接绑定 列名 就可以了, 我晕死 太菜了