Creating an xml-based application in asp.net2.0

Source: Internet
Author: User
Tags data structures datetime new features table name

XML is a common technology currently applied on the Web, and in. NET 2.0, it provides richer functionality that makes it easier to create XML applications. In this article, a simple example is given to illustrate some of the new features of. NET 2.0 when creating XML applications.

First, we usually choose to store data in the form of a database when we create a Web application, but it can be a challenge if we want to store data in pure XML. In the. NET 1.0/1.1 Framework, support for XML is limited, such as support for multiple XML files in the same application. In. NET 2.0, this situation has been changed to add new features, such as:

1. The DataTable can now read and write XML data.

2, using the Datgridview control, allows you to display data from different tables in the dataset.

I'll illustrate these new features in a Web application example below. In this program I store all the data in an XML file. Shows how to read and write multiple XML files simultaneously in a dataset, how to bind XML files to DataGridView controls, and show how DataGridView controls can read and write data from XML files and find data in multiple XML files. These new features are not in the previous. Net.

Task Tracking Application

Next, we will create a Web application that implements task tracking. This application is actually very simple and can help you keep track of the progress of some tasks and activities. It needs to create two XML files: Activities.xml and Tasks.xml files. The activites file stores daily activities, including what tasks are required for each activity, the description of the task, the time of the start and end. The tasks file holds the type of task, such as browsing email, writing programs, reading books, etc. The following figure shows the data structure between these two files.

Data structures between two files

Typically, you might want to create these two XML files by hand, but this is not actually advocated, because in Vs.ne 2005, you can use the DataSet Designer to help you design the structure of the XML file, allowing you to create the XML file for the graph relationship, which is specifically solved below.

1 Open visual.net 2, create a new Windows application, select the VB.net language, name the project Dtkxml, and then add a dataset-type file and name it dsactivitiestasks. Then add two tables, activities and Tasks table (see Figure 1). Only in the designer interface, right-click the mouse, in the pop-up menu selected add->datatable can be.

Next, to the table name of each table, right-click the mouse, select Add->column in the pop-up menu, add columns for each table, where the name of each column, attributes, and data types are shown in the following table:

Activites table

Column Name Property
1 ActivityID Datatype=system.int32

Autoincrement=true

Autoincrementseed=1

Autoincrementstep=1

Unique=true

2 TaskID Datatype=system.int32
3 Description Datatype=system.string
4 Startime Datatype=system.datetime
5 Endtime Datatype=system.datetime

Tasks table

 

Column Name Property
1 TaskID Datatype=system.int32

Autoincrement=true

Autoincrementseed=1

Autoincrementstep=1

Unique=true

Allowdbnull=false

2 Task Datatype=system.string

Allowdbnull=false

Next, it is very simple to establish an association for these two XML files. In the Activities and Task table Design view state, click the right mouse button, select "Add relation" in the pop-up menu, and set two file associations as shown in the following figure.

Set two files for correlation

2 This time, we can design the interface of the application. The application consists of two forms, the first form, which allows the user to process information about the activity, and the second form, which can be provided to the user to edit various types of tasks.

Rename the default form in the project to Frmactivities and drag a DataGridView control to the form in the toolbox. Next, notice that the smart tag tag in the upper-right corner of the control is selected, and a menu appears (as shown in the following image), choosing Dsactivitiestasks (the DataSet type file we just created) as the DataGridView data source.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.