/// <summary> /// 获取DataSet的Xml格式 /// </summary> public static string GetDataSetXml(this DataSet 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("<", "<").Replace(">", ">") + "</" + clName + ">"; } str += "</" + dataSet.Tables[k].TableName + ">"; } } str += "</NewDataSet>"; str = str.Replace("&", "&"); str = str.Replace("‘", "'"); str = str.Replace("\"", """); return str; }
有时我们需要对整个DataSet进行加密,但是很少有直接对DataSet进行加密的方法,所以要想办法将DataSet转化成String类型在进行加密,然后传送。
接收到加密XML后用StringReader将数据读入DataSet
DataSet dsLV = new DataSet(); string decryptedData = Decrypt(xmlDSLV); //解密XML数据源 StringReader sr = new StringReader(decryptedData); dsLV.ReadXml(sr); //将数据读入DataSet sr.Close();
时间: 2024-10-12 07:36:12