WebForm3.aspx |
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="WebForm3.aspx.vb" Inherits="WebApplication12.WebForm3" %> |
WebForm3.aspx.vb |
Imports System.Data.SqlClient Partial Public Class WebForm3 Inherits System.Web.UI.Page Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Head("RSS", "http://127.0.0.1", "Testing RSS") Get_Data() Complete() End Sub Sub Head(ByVal Title As String, ByVal Link As String, ByVal Description As String) Response.Write("<rss version=""2.0"">") Response.Write("<channel>") Response.Write("<title>" & Title & "</title>") Response.Write("<link>" & Link & "</link>") Response.Write("<description>" & Description & "</description>") End Sub Sub Complete() Response.Write("</channel>") Response.Write("</rss>") End Sub Sub Content(ByVal Title As String, ByVal Link As String, ByVal Description As String) Response.Write("<item>") Response.Write("<title>" & Title & "</title>") Response.Write("<link>http://127.0.0.1/news/" & Link & ".aspx</link>") Response.Write("<description>" & Description & "</description>") Response.Write("</item>") End Sub Sub Get_Data() Dim connectionString1 As String = "Data Source=.\SqlExpress; Initial Catalog=Soccer; Integrated Security=SSPI" Dim con1 As SqlConnection = New SqlConnection(connectionString1) con1.Open() Dim SqlString1 As String = "SELECT * FROM News" Dim cmd1 As SqlCommand = New SqlCommand(SqlString1, con1) Dim dr As SqlDataReader = cmd1.ExecuteReader() If dr.HasRows Then Do While dr.Read Content(dr.Item("News_Name").ToString.Trim(), _ dr.Item("News_ID").ToString.Trim(), _ dr.Item("News_Content").ToString.Trim()) Loop End If dr.Close() con1.Close() con1.Dispose() End Sub End Class |