The dataset merges a dataset into a set of datasets

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.