DataSet.DataTable.DataRow(单个)到 XML 字符串
我当前正在处理的项目中有强类型数据集,我需要将 DataRow 对象从 DataSet(DataSet 中只有 1 个 DataTable)转换为 XML 字符串。我尝试了以下方法,但完全失败了:
string originalXmlString = string.Empty;
DataSet ds = new DataSet();
ds.Tables.Add(this.ObjectDataRow.Table);
ds.Tables[0].ImportRow(this.ObjectDataRow);
using (StringWriter sw = new StringWriter())
{
ds.Tables[0].WriteXml(sw);
originalXmlString = sw.ToString();
}
req.OriginalDataRow = originalXmlString;
任何帮助将不胜感激!
谢谢, 基思
I have strongly-typed datasets in the project that I am currently working on and I need to convert a DataRow object from the DataSet (only 1 DataTable in the DataSet) to an XML string. I attempted the following with only utter failure:
string originalXmlString = string.Empty;
DataSet ds = new DataSet();
ds.Tables.Add(this.ObjectDataRow.Table);
ds.Tables[0].ImportRow(this.ObjectDataRow);
using (StringWriter sw = new StringWriter())
{
ds.Tables[0].WriteXml(sw);
originalXmlString = sw.ToString();
}
req.OriginalDataRow = originalXmlString;
Any help would be greatly appreciated!
Thanks,
Keith
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我能够在有关 Clone() 函数。
以下代码经过修改并且效果很好:
I was able to figure it out with the assistance of a MSDN page regarding the Clone() function.
The following code is revised and works great: