如何将字符串转换为system.data.dataset [英] how to convert string to system.data.dataset

查看:80
本文介绍了如何将字符串转换为system.data.dataset的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的网络方法中,我正在这样做

In my webmethod., i am doing this

[WEBMETHOD]
 XDocument xd = XDocument.Load(@"D:\satish1\na.xml");
            var query = from p in xd.Descendants("item")
                        select new
                        {
                            name = p.Element("title").Value,
                            des = p.Element("description").Value
                        };
            return query.ToString();



当我想使用此方法时,我正在编写此



when I want to consume this method , i am writing this

WpfApplication1.ServiceReference1.Service1SoapClient proxy = new WpfApplication1.ServiceReference1.Service1SoapClient();
            DataSet ds = proxy.getdetails();
          
            ds.WriteXml(@"D:\satish1\sb.xml", XmlWriteMode.WriteSchema);


我无法使用ds.write xml方法,并将xml输出保存在我的系统中.就是说无法转换system.data.dataset,
在我的webmethod iam中,返回字符串是否可以在其中返回xml,也可以在代理调用中将该字符串转换为system.data.dataset.

请以一些代码告诉我.


I am not able to use ds.write xml method ,and save the xml output in my system. It is saying cannot convert system.data.dataset,
In my webmethod iam returning strings can i return xml there, also in my proxy call can I convert that string to system.data.dataset.

please tell me in some code

推荐答案

问题是逻辑完全中断的结果.假设编译器告诉您无法将A型转换为B型".用这个事实来问一个问题好吧,我怎么能将A转换成B?"是非常不合逻辑的.恰恰相反,这很可能表明在期望使用B型的情况下使用A型根本没有意义.

询问有关将字符串转换"为DataSet的问题.这个不成立.通常,字符串是字符串,除了可能是另一个代表字符串概念的技术表示形式的对象(例如,以空字符结尾的字符串或其他内容)之外,它不会转换"为任何东西.

即使在相同情况下,字符串也可以表示数据集,但是没有诸如转换"之类的操作.可以将某些对象或对象图进行序列化为某种格式的字符串,例如,基于XML或JSON的字符串,反序列化用于重新创建对象或与原始图等效的对象图.可能是解析这种格式.无论是什么,都不能称为转换".

在您的代码示例中,您的DataSet可能没有您要纠正的当前架构.在这种情况下,根据 http://msdn.microsoft.com/zh-cn/library/system.data.xmlwritemode.aspx [
The question is a result of totally broken logic. Suppose a compiler tells you "cannot convert type A into type B". It is very illogical to use this fact to ask a question "OK, and how can I convert A into B?". Just the opposite, it''s most likely the indication that using the type A where type B is expected simply makes no sense.

Take a question about "conversion" of a string into a DataSet. It makes no sense. Generally string is a string, it is not "converted" into anything except may be another object which is a different technical representation of the idea of string, such as null-terminated string or something else.

Even though in same cases a string can represent a Dataset, but there is no such operation as "conversion". It can be serialization of some object or object graph into a string in some format, for example, based on XML or JSON, which deserialization used to re-create an object or an object graph equivalent to original one. It could be parsing of such format. Whatever it is, it cannot be called "conversion".

In your code sample, your DataSet probably has no current schema you are trying to right. In this case you cannot right anything, according to http://msdn.microsoft.com/en-us/library/system.data.xmlwritemode.aspx[^].

It is not clear to me where your exception comes from, as you did not clearly indicate what did you face with: an exception or compilation error, what was exact message, line of code and other relevant information. You should always provide such information in a comprehensive way when asking questions.

—SA


这篇关于如何将字符串转换为system.data.dataset的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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