Sorts the content in the datatable and splits the content into multiple datatable

Source: Internet
Author: User
Sort datatable:
Datarow [] DR = DT. Select ("A0 is not null", "A0 ASC ");
Datatable dt1 = DT. Clone ();
Dt1.rows. Clear ();
For (I = 0; I <DT. Rows. Count; I ++)
{
Datarow irow = dt1.newrow ();
For (Int J = 0; j <DT. Columns. Count; j ++)
{
If (Dr [I] [J]! = NULL)
If (Dr [I] [J]. tostring ()! = "")
Irow [J] = Dr [I] [J]. tostring ();
}
Dt1.rows. Add (irow );
}
Return dt1;

Split the datatable:
Private string datatable (datatable DT)
{
Int dtindex = DT. Rows. Count; // retrieves the total number of DT rows.
Int Index = 0, I = 0, Index = 0; // index indicates the number of data rows.
String datarow, err = "";
Datarow = DT. Rows [0] [0]. tostring (); // retrieve the ticket number of the first record
// If the total number of rows is not equal to 0
Sqlconnection con = new sqlconnection (sqlhelper. toeposconnstring );
Con. open ();
While (dtindex! = Index) // 11
{
Datarow [] DR = DT. Select ("a0 = '" + datarow. tostring () + "'"); // retrieve the total number of ticket numbers
Index = dr. length; // The number of rows from the new dr.
Datatable dt1 = DT. Clone ();
Dt1.rows. Clear ();
For (I = 0; I <index; I ++) // Add the new row to the new able.
{
Datarow irow = dt1.newrow ();
For (Int J = 0; j <DT. Columns. Count; j ++)
{
If (Dr [I] [J]! = NULL)
If (Dr [I] [J]. tostring ()! = "")
Irow [J] = Dr [I] [J]. tostring ();
}
Dt1.rows. Add (irow );
}
Err = inserttodatabase (dt1, con); // call the method to write the values in the new able into the database
Index = index + index;
If (Index = dtindex)
Break;
Datarow = DT. Rows [Index] [0]. tostring ();
}
Con. Close ();
Return err;
}

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.