datatable行和列的问题
按照顺序,分1234图(从左到又)
我要从数据库调出数据,绑定到gridview里面,将多行改成一行输出,现在的问题是,可以改成行输出,可是数据库里面有多少行,gridview里面就有多少行,效果就是图2
我现在想要实现图四+三的结合,也就是一行?哪位帮我看看
程序代码:
DataTable flattable=hii.floatta(str20); DataView flatview = new DataView(flattable); DataView flatta = new DataView(flattable); DataTable lottable =hii.lottab(flatview); DataTable defecttables = hii.qd(); crosstable.Columns.Add("CLAIMDATETIME", typeof(string)); crosstable.Columns.Add("LOTNO", typeof(string)); crosstable.Columns.Add("WO", typeof(string)); crosstable.Columns.Add("PRODUCTNO", typeof(string)); crosstable.Columns.Add("PRODUCTNAME", typeof(string)); crosstable.Columns.Add("P_LOT_BRANCHNO", typeof(string)); crosstable.Columns.Add("USED_MATE01", typeof(string)); crosstable.Columns.Add("USED_MATE02", typeof(string)); crosstable.Columns.Add("type_04", typeof(string)); crosstable.Columns.Add("INSPECTOR", typeof(string)); crosstable.Columns.Add("INPUTUSER", typeof(string)); crosstable.Columns.Add("REMARK", typeof(string)); crosstable.Columns.Add("QTY_PROD", typeof(float)); crosstable.Columns.Add("OKQTY_PROD", typeof(float)); crosstable.Columns.Add("A_RATE", typeof(float)); crosstable.Columns.Add("BAD_QTY", typeof(float)); crosstable.Columns.Add("B_RATE", typeof(float)); crosstable.Columns.Add("qian_qtys", typeof(float)); crosstable.Columns.Add("qian_qty", typeof(float)); crosstable.Columns.Add("hou_qtys", typeof(float)); crosstable.Columns.Add("hou_qty", typeof(float)); crosstable.Columns.Add("P_OLD_LOTNO", typeof(string)); crosstable.Columns.Add("PROD_STATUS", typeof(string)); crosstable.Columns.Add("SPNUM_STATUS", typeof(string)); crosstable.Columns.Add("M2_INSPECTMETHOD", typeof(string)); foreach (DataRow r in defecttables.Rows) { crosstable.Columns.Add(r[0].ToString(), typeof(float)); } DataColumnCollection cols = crosstable.Columns; foreach (DataRow r in lottable.Rows) { DataRow newrows = crosstable.NewRow(); newrows["CLAIMDATETIME"] = r[0]; newrows["LOTNO"] = r[1]; newrows["WO"] = r[2]; newrows["PRODUCTNO"] = r[3]; newrows["PRODUCTNAME"] = r[4]; newrows["P_LOT_BRANCHNO"] = r[5]; newrows["USED_MATE01"] = r[6]; newrows["USED_MATE02"] = r[7]; newrows["type_04"] = r[8]; newrows["INSPECTOR"] = r[9]; newrows["INPUTUSER"] = r[10]; newrows["REMARK"] = r[11]; newrows["QTY_PROD"] = r[12]; newrows["OKQTY_PROD"] = r[13]; newrows["A_RATE"] = r[14]; newrows["BAD_QTY"] = r[15]; newrows["B_RATE"] = r[16]; newrows["qian_qtys"] = r[17]; newrows["qian_qty"] = r[18]; newrows["hou_qtys"] = r[19]; newrows["hou_qty"] = r[20]; newrows["P_OLD_LOTNO"] = r[21]; newrows["PROD_STATUS"] = r[22]; newrows["SPNUM_STATUS"] = r[23]; newrows["M2_INSPECTMETHOD"] = r[24]; for (int i = 25; i < cols.Count; i++) { flatview.RowFilter = String.Format("lotno='{0}' and DEFECTITEM='{1}'", r[1], defecttables.Rows[i-25][0]); if (flatview.Count > 0) { newrows[cols[i]] = flatview[0]["data"]; } } crosstable.Rows.Add(newrows); // DataTable cc= crosstable.DefaultView.ToTable(true,new string []{"lotno"}); } gv1.Visible = true; gv1.DataSource = crosstable.DefaultView; gv1.DataBind(); t4.Text = "總共有" + crosstable.Rows.Count.ToString() + "行 ";