Ajax realizes the display function of RSS Channel

Source: Internet
Author: User

When the page is loaded, it is required to display all channel names in the database in the list of channels, which is the display function of the RSS channel. This section mainly implements this feature.

Designing ways to read the contents of a database

Read the contents of the database, first of all to design the method of reading data. The method in this example is best added to the Rssmanager management class. The steps to implement the method are as follows:

(1) Open the "Rssmanager" management class file under the App_Code directory.

(2) Add the method "Getrssname" to the class, primarily by reading the channel name from the database and saving the returned results in an array. Note When you use the array "ArrayList", you must reference the namespace "using System.Collections;". The actual implementation code is shown in Listing 12-8.

Code listing 12-8 ways to get data from a database

public string[] Getrssname ()
{
//Initializing SQL command
SqlCommand cmd = new SqlCommand ();
       Executes the SQL command within a scope, releasing all objects
using (SqlConnection conn = new SqlConnection (connectionString))
After the scope has ended {
//To determine the database connection state
if (conn). State!= ConnectionState.Open)
Conn. Open ();
Cmd. Connection = conn;
//define command properties
Cmd.commandtype = CommandType.Text;
Cmd.commandtext = "Select Rss_name,rss_url from Rssstore";
//execute command and return data
SqlDataReader rdr = cmd. ExecuteReader (commandbehavior.closeconnection);         
//define an array to return
ArrayList myarray = new ArrayList ();
The loop determines whether there is data
while rdr. Read ())
{
//If there is data, it is stored in an array, where the data is separated by a comma between
MyArray. ADD (RDR. GetString (0) + "," + rdr. GetString (1));       
}
Return myarray
}
}

(3) According to "Ctrl+s" to save the design of the code.

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.