[已解决]请帮忙,将XML加载到DataGridView时出现问题 [英] [Solved] Please help, Problem in loading XML into DataGridView

查看:61
本文介绍了[已解决]请帮忙,将XML加载到DataGridView时出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用"dataset.GetXml"将我的xml生成为变量字符串str",然后使用"sFile.WriteLine(str)"将包含在变量str中的xml"写入"file.xml". sFile是流阅读器.

我之所以使用``writeline''而不是``dataset.WriteXml''的原因是因为我需要先加密存储在``str''中的``xml'',然后再将其存储到file.xml中.

对于加密结果,我一切都很好,解密结果也是如此.

这是下面我的file.xml的解密结果(我已经在加密之前的str和解密的file.xml中检查了它的xml值.它们都匹配得很好)

-------------------------------------------------- ----------------------

I generate my xml into "variable string str" by using "dataset.GetXml" and then I write the "xml which is contained in variable str" into "file.xml" by using "sFile.WriteLine(str) while ''sFile'' is a stream reader"

My reason for using ''writeline'' instead of ''dataset.WriteXml'' because I need to encrypt the ''xml stored in ''str'' before I store it into file.xml.

I got everything fine for the encrypted result, and so does the decrypted result as well.

Here''s the decrypted result of my file.xml below (I have checked it the xml value which in str before encryption and which in decrypted file.xml. They are all match well)

------------------------------------------------------------------------

<newdataset>
       <table>
             <title> Book 1 <title/>
             <addby />
             <date>2010-09-22T14:43:00.0000000+07:00</date>
       </table>
</newdataset>



-------------------------------------------------- ----------------------

这是我的原始xml值,在它被加密或解密之前,我通过使用GetXml将其存储在变量str中.我不确定,但是我的xml值不包含声明",就像以前的通用xml一样.

我从GetXml获得的所有xml文件都如下所示(没有类似
的声明



------------------------------------------------------------------------

Here is my plain xml value before it got encrypted or decrypted which I stored it in variable str by using GetXml. I don''t know for sure but my xml value doesn''t contain declaration "" like common xml used to have.

All the xml file which I got from GetXml is just like below (No declaration like

)

<newdataset>
       <table>
             <title> Book 1 <title/>
             <addby />
             <date>2010-09-22T14:43:00.0000000+07:00</date>
       </table>
</newdataset>





-------------------------------------------------- -----------------------


而且由于我认为这可能不会造成任何问题,所以我继续对其进行编码和解密,一切进展顺利,解密结果当然是完全一样的.

我的问题是,当我尝试使用下面的代码使xml值显示在Data GridView中并运行调试时,它提示错误消息找不到文件c:\ bla \ File.xml".请帮助并感谢您的任何评论或建议.





-------------------------------------------------------------------------


And since I think it may not cause any problem then I keep coding and decrypt it which is going well and the decrypted result is perfectly same ofcourse.

My problem is, when I try to make my xml value show in Data GridView by using the code below, and run the debug, it prompt an error said "could not find the file c:\bla\File.xml ". Please help and thanks for any reviewing or suggestion too.

ds = New DataSet
path = System.IO.Path.GetFullPath(strFileToDecrypt)
ds.ReadXml(path)
DGV.DataSource = ds



(strFileToDecrypt是从SaveFileDialog存储".FileName"的字符串)


更新:
由OP自己解决.



(strFileToDecrypt is string which stored ".FileName" from SaveFileDialog)


UPDATE:
Solved by OP himself. Posted as an answer.

推荐答案

此后,我急着努力,得到了自己的解决方法,该方法非常有效.
在创建一个消息框之前,我从来没有想过自己回答它,直到现在我得到了答案.

我的问题就在路径上,这是我的代码起作用了.
After, I hurry in my effort, I got my own solving way which really working good.
I never think to answer it mayself until I make a message box this is it just now and I got the answer hore.

My problem just in the path and here''s my code which worked.
xmlDatadoc = New XmlDataDocument
path = System.IO.Path.GetFullPath(pk)
MsgBox("Ini Dia" & path)
xmlDatadoc.DataSet.ReadXml(path)
ds = New DataSet
ds = xmlDatadoc.DataSet
DGV.DataSource = ds.DefaultViewManager



很高兴解决这个问题.^^



Happy to solve it.^^


这篇关于[已解决]请帮忙,将XML加载到DataGridView时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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