/// <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.