Example of basic Ajax principles part. II

Source: Internet
Author: User
We usually use the teachsamples database to have a bbc_country table. Now we need to use Ajax technology for an application: To create an HTML page, we can refresh the data changes in the bbc_country table, including the addition, deletion, and modification of each record, and the display of different query results on the HTML page without refreshing based on different conditions.

For more information, see examples.

Note that the preceding example is not complete:

1. The data in this example comes from http://www.koonsoft.net/samples/ajax/bbc_country.xml, but this data source will not change and does not meet the requirements for reflecting data changes.

2. In this example, data is not reloaded according to region.

How to read data from the database and generate xml, I provide a C # console applicationProgramFor your reference:

Code
Using System;
Using System. Collections. Generic;
Using System. text;
Using System. Data;
Using System. Data. sqlclient;
Using System. IO;
Using System. text;
Using System. xml;

Namespace Getxml
{
Public   Class Program
{
Static   Void Main ( String [] ARGs)
{
Sqlconnection sqlconn =   New Sqlconnection ();
Sqlconn. connectionstring =   " Password = ******; persist Security info = true; user id = sa; initial catalog = teachsamples; Data Source = 127.0.0.1 " ;

sqlcommand sqlcmd = New sqlcommand ();
sqlcmd. commandtext = " select * From bbc_country order by name " ;< br> sqlcmd. connection = sqlconn;

Xmlwriter writer= Null;

Try
{

// Create an xmlwritersettings object with the correct options.
Xmlwritersettings settings =   New Xmlwritersettings ();
Settings. indent =   True ;
Settings. indentchars = ( " \ T " );
Settings. omitxmldeclaration =   False ;

// Create the xmlwriter object and write some content.
Writer = Xmlwriter. Create ( " Bbc_country.xml " , Settings );

Writer. writestartdocument ();
Writer. writestartelement ( " Countries " );

Try
{
Sqlcmd. Connection. open ();
Sqldatareader sqlrd = Sqlcmd. executereader ();
While (Sqlrd. Read ())
{
Writer. writestartelement ( " Country " );
Writer. writestartelement ( " Name " );
Writer. writestring (sqlrd [ " Name " ]. Tostring ());
Writer. writeendelement ();
Writer. writestartelement ( " Region " );
Writer. writestring (sqlrd [ " Region " ]. Tostring ());
Writer. writeendelement ();
Writer. writestartelement ( " Area " );
Writer. writestring (sqlrd [ " Area " ]. Tostring ());
Writer. writeendelement ();
Writer. writestartelement ( " Population " );
Writer. writestring (sqlrd [ " Population " ]. Tostring ());
Writer. writeendelement ();
Writer. writestartelement ( " GDP " );
Writer. writestring (sqlrd [ " GDP " ]. Tostring ());
Writer. writeendelement ();
Writer. writeendelement ();
}
}
Finally
{
Sqlcmd. Connection. Close ();
}

Writer. writeendelement ();
Writer. writeenddocument ();

Writer. Flush ();
}
Finally
{
If (Writer ! =   Null )
Writer. Close ();
}
}
}

 

 

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.