usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingsystem.web;usingSystem.Web.UI;usingSystem.Web.UI.WebControls;usingSystem.Configuration;usingSystem.Data;usingSystem.Data.SqlClient;namespaceqqisonline{ Public Partial classIndex1:System.Web.UI.Page {protected voidPage_Load (Objectsender, EventArgs e) { if(!IsPostBack) {Gridview1.datasource=Getqqinfo (); Gridview1.databind (); Gridview2.datasource=GetOrderInfo (); Gridview2.databind (); Gridview3.datasource=Getdatabycount (); Gridview3.databind (); } } stringSqlconnstr = configurationmanager.connectionstrings["MyDB"]. ToString (); //Get QQ Information PublicDataSet Getqqinfo () {using(SqlConnection sqlconn =NewSqlConnection (SQLCONNSTR)) { stringSqlstr ="SELECT * from Qqinfo"; SqlDataAdapter SDA=NewSqlDataAdapter (Sqlstr,sqlconn); DataSet DS=NewDataSet (); Sda. Fill (DS); returnds; } } //get the total number of each buckle number in the order PublicDataSet GetOrderInfo () {using(SqlConnection sqlconn =NewSqlConnection (SQLCONNSTR)) { stringSqlstr ="Select COUNT (orderinfo. ID) as num,qq from OrderInfo Group by QQ ORDER by Num Desc"; SqlDataAdapter SDA=NewSqlDataAdapter (Sqlstr, sqlconn); DataSet DS=NewDataSet (); Sda. Fill (DS); returnds; } } /// <summary> ///consolidate data from two datasets///Append the order quantity for each customer service to the back of the DataTable/// </summary> /// <returns>a new collection</returns> PublicDataTable Getdatabycount () {DataSet Dtordet= GetOrderInfo ();//collection of order volume totals per customer serviceDataSet dtqq = Getqqinfo ();//Customer Service data collectionDtqq. tables[0]. Columns.Add ("COLUNM",typeof(string));//add a new column to the customer service collection for(inti =0; I < Dtordet. tables[0]. Rows.Count; i++)//iterate through the collection of each customer service order Volume summary { stringQQ = Dtordet. tables[0]. rows[i]["QQ"]. ToString ();//get the QQ number of the linedatarow[] Dr = Dtqq. tables[0]. Select ("qq="+ QQ);//whether this ID is included in the customer Service data collection if(Dr. Length.equals (1))//include { intK = dtqq. tables[0]. Rows.indexof (dr[0]);//record the line number of the row data! stringnum = Dtordet. tables[0]. rows[k]["Num"]. ToString ();//get the number of orders for the row dataDtqq. tables[0]. rows[i]["COLUNM"] = num;//Add Column Data}} DataView dv= Dtqq. tables[0]. DefaultView; Dv. Sort="COLUNM DESC";//sort data in descending order based on volume returnDV. ToTable (); } }}
The results are as follows:
The dataset merges a dataset into a set of datasets