从XML文件中提取数据&在GridVIew中显示它(ASP.NET C#) [英] Extracting Data From XML File & Showing it in GridVIew(ASP.NET C#)

查看:54
本文介绍了从XML文件中提取数据&在GridVIew中显示它(ASP.NET C#)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

HI朋友,



我是ASP.NET的新手...



In我的办公室我没有权限访问SQL,我想执行一些数据库相关的任务,比如绑定数据来控制或gridviewo更新我的练习数据...



由于我无法访问SQL,我正在考虑使用XML文件作为我的数据库.......



所以你能告诉我如何提取来自XML文件的数据并将其绑定到GridView控件.....?

HI friends,

I'm new to ASP.NET...

In my office I dont have permission to access SQL, & I want to perform some database related task like binding data to control or gridviewo updating data for my practise...

As I dont have access to SQL I'm thinking of using XML file as my DATABASE.......

so can u please tell me how to extract data from XML File and Binding it to GridView Control.....?

推荐答案

XML文件原则上不能是数据库。但它可以用作某些数据模型的存储层,该数据模型在应用程序的生命周期内完全存储在内存中。在这种情况下,数据层和存储层实际上可以用作一种数据库。



将数据层与数据层分开非常重要存储层。例如,您需要在内存中执行搜索,而不是在XML中,更新内存,执行事务。 XML应仅在您确实需要将数据存储在磁盘上时使用。



最好的方法是使用数据合同:http://msdn.microsoft.com/en-us/library/ms733127.aspx [ ^ ]。



如果你这样做,你可以忘记XML:一切都已经完成了。序列化程序只是将任何对象图存储到内存中,并以完全相同的方式从文件或流中恢复它。我的意思是:任意拓扑的对象图,而不仅仅是树(这意味着,图表允许有循环引用,这对于关系模型至关重要)。这种方法最强大,同时也是最容易使用的方法。它是非侵入式的:您只定义数据类,序列化由合同定义并且已经完成。基本上,您所做的只是向数据类型和成员添加一些属性,这不会限制或修改类型的行为。



请参阅我过去的答案,我提倡这种方法:

如何在表单应用程序中使用XML文件编写器和阅读器? [ ^ ],

创建属性文件...... [ ^ ]。



-SA
An XML file cannot be a database in principle. But it can be used as a storage layer for some data model which is fully stored in memory during the lifetime of the application. In this case, the data layer along with the storage layer can really be used as a kind of a database.

It is really important to separate the data layer from the storage layer. For example, you need to perform the search in memory, not in XML, update memory, do transaction. XML should be only used when you really need to store the data on disk.

The best approach would be using Data Contract: http://msdn.microsoft.com/en-us/library/ms733127.aspx[^].

If you do it, you can forget XML: everything is already done for you. The serializer simply store any object graph to memory and restore it in exact same way in memory from a file or a stream. I mean it: an object graph of arbitrary topology, not just a tree (it means, the graph is allowed to have circular references, which is critically important for relational model). This approach is the most robust and at the same time is the easiest to use. It is non-intrusive: you only define your data classes, the serialization is defined by the contract and is already done. Basically all you do is adding some attributes to data types and members, which does not limit or modify behavior of your types.

Please see my past answers where I advocate this approach:
How can I utilize XML File streamwriter and reader in my form application?[^],
Creating property files...[^].

—SA


这篇关于从XML文件中提取数据&在GridVIew中显示它(ASP.NET C#)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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