Convert dataset to the string type in XML format and then return it.

Source: Internet
Author: User
/// <Summary> /// get the XML format of dataset /// </Summary> Public static string getdatasetxml (This dataset) {string STR = string. empty; STR + = "<newdataset>"; for (int K = 0; k <dataset. tables. count; k ++) {for (INT I = 0; I <dataset. tables [K]. rows. count; I ++) {If (Dataset. tables [K]. tablename = "") {dataset. tables [K]. tablename = "table" + k;} STR + = "<" + dataset. tables [K]. tablename + ">"; for (Int J = 0; j <dataset. tables [K]. columns. count; j ++) {string clname = dataset. tables [K]. columns [J]. columnname; STR + = "<" + clname + ">" + dataset. tables [K]. rows [I] [clname]. tostring (). replace ("<", "& lt ;"). replace (">", "& gt;") + "</" + clname + ">";} STR + = "</" + dataset. tables [K]. tablename + ">" ;}}str + = "</newdataset>"; STR = Str. replace ("&", "& amp;"); STR = Str. replace ("'", "& apos;"); STR = Str. replace ("\" "," & quot; "); Return STR ;}

Sometimes we need to encrypt the entire dataset, but there are few methods to encrypt the dataset directly. Therefore, we need to convert the dataset to the string type for encryption and then transmit the data.

After receiving the encrypted XML, use stringreader to read the data into dataset.

Dataset dslv = new dataset (); string decrypteddata = decrypt (xmldslv); // decrypt the XML data source stringreader sr = new stringreader (decrypteddata); dslv. readxml (SR); // read data into dataset Sr. close ();

 

Convert dataset to the string type in XML format and then return it.

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.