将数据从数据表写入xml [英] Writing Data From Datatable into xml

查看:126
本文介绍了将数据从数据表写入xml的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 DataTable dts =  DataTable();
                             dts.Columns.Add(" );
                             dts.Columns.Add(" );
                             dts.Columns.Add(" );
                             DataRow drs = dts.NewRow();
                             字符串heading_name = dr [" ].ToString();
                             drs [" ] =标题名称;
                             字符串detail_text = dr2 [" ].ToString();
                             drs [" ] = detail_text;
                             dts.Rows.Add(drs);
                             DataSet mDs =  DataSet();
                             dts.TableName = " ;
                             mDs.Tables.Add(dts);
                             mDs.WriteXmlSchema(Server.MapPath(" ).ToString());  pre> 
我有一个datatable,添加了列,然后添加了从foreach循环分配的数据行.然后,我创建一个数据集,将我的数据表添加到其中,并调用writexmlschema方法.问题是创建了我的XML文件,但是我有列而不是来自数据库的实际数据.我在调试模式下也看到了变量数据的到来,但在XML中仅显示了列名.

我希望它可以将数据库中的数据写入XML中,有人可以帮助我吗?



OP像成年人一样说话.同意英语很差,所以我已将其修复

原始文本显得幼稚的原因是由于阿拉伯字母(在巴基斯坦使用)的工作方式:字母"Tha" ﺙ使声音听起来像希腊的Theta或Booth.字母dhal ﺫ也听起来像是"th"(但是像" th is"或" th e"一样,而不是"boo ") ),但通常音译为"dh"或有时是"d". OP所做的只是选择了错误但常见的英语音译.这类似于德国人混淆了v/w和阿拉伯人混淆了b/p和f/v或英国人为此混淆了ﺱ/ﺹ或ﺡ/ﺥ/ﻩ或ﻕ/ﻙ或ﺽ/ﺩ.不幸的是,对于OP来说,它的确听起来像是在讲小孩子的声音,因为他困惑的字母听起来就像是一个还不能正确形成"th"声音的孩子一样.另外,OP还没有使用标点符号,因为阿拉伯文本通常不需要标点符号.

解决方案

调用 WriteXmlSchema 方法是问题.这写出了模式,该模式是XML文件应包含的定义以及它的结构(例如预期的标签,属性).调用WriteXml有望解决您的问题.


TanzeelAhmed写道:

在即时通讯中我



在这一点上,我认为您显然是个白痴,并且不再阅读任何内容.


TanzeelAhmed写道:

da问题是,马



我向前扫描.是的,你是个白痴.

这是一个说英语的网站,到处都是成人.像成年人一样说话.

我不同意100%的评论基思. OP未使用语音或拼写有问题.他使用的是孩子在手机上使用的txtspeak.我就是反对的.拼写不好,语法不好等,我一点都没问题.


亲爱的上帝,Jar Jar Binks终于找到了Code Project.


DataTable dts = new DataTable();
                             dts.Columns.Add("heading_name");
                             dts.Columns.Add("sub_heading_name");
                             dts.Columns.Add("detail_text");
                             DataRow drs = dts.NewRow();
                             string heading_name = dr["heading_name"].ToString();
                             drs["heading_name"] = heading_name;
                             string detail_text = dr2["detail_text"].ToString();
                             drs["detail_text"] = detail_text;
                             dts.Rows.Add(drs);
                             DataSet mDs = new DataSet();
                             dts.TableName = "MyTable";
                             mDs.Tables.Add(dts);
                             mDs.WriteXmlSchema(Server.MapPath("XMLFile.xml").ToString());


I have a datatable, added columns and then I add datarows assigning from foreach loop. Then I create a dataset adding my datatable to it and call writexmlschema method. The problem is that my XML file is created but I it has columns not the actual data which is comin from database. I have watched in debug mode also in my variable data is coming but in XML only columns name are being shown.

I want it to write my data from the database into XML can anybody help me?



[Edit Keith Barrow:] The OP is speaking like an adult. Agreed the English is pretty poor, so I''ve fixed it

The reason the orignal text looked childish is because of the way the Arabic alphabet(used in Pakistan) works: The letter "Tha" ﺙ makes the sound "th" like the greek Theta or Booth. The letter dhal ﺫ which also sounds "th" (but as in "this" or "the" rather than "booth") but is normally transliterated to "dh" or sometimes "d". What the OP did was choose a wrong, but common English transliteration. This is akin to a German mixing up v/w and Arabs confusing b/p and f/v or English people confusing ﺱ/ﺹ or ﺡ/ﺥ/ﻩ or ﻕ/ﻙ or ﺽ/ﺩ for that matter. Unfortunately for the OP it does look like kiddie-speak because the letters he has confused happen sound the same as a child who can''t form the "th" sound properly yet. Additionally the OP has also not used punctuation as Arabic text doesn''t usually need it.

解决方案

Calling the WriteXmlSchema method is the problem. This writes out the schema which is a definition od what XML file should contain and it structure (e.g.expected tags, attributes). Calling WriteXml instead will hopefully fix your problem.


TanzeelAhmed wrote:

in dis wat i m doin i



At this point I decided you''re clearly a moron, and didn''t read any more.


TanzeelAhmed wrote:

da problem is that ma



I scanned ahead. Yep, you ARE a moron.

This is an English speaking site, full of adults. Speak like an adult.

I disagree 100% with your comments Keith. The OP was not using phonetics, or having trouble with spelling. He was using the txtspeak that children use on their mobile phones. That is what I object to. Poor spelling, bad grammar, etc, I have no issue with at all.


Dear god, Jar Jar Binks finally found Code Project.


这篇关于将数据从数据表写入xml的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆