hi i need to save rss to sql
every day first load read and write sql and other read from my db
Imports System.ServiceModel.Syndication
Imports System.Xml
Imports System.Data
Imports System.Data.SqlClient
Partial Class _Example4
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim RSSReader As XmlReader = XmlReader.Create(ConfigurationManager.AppSettings("rssUri"))
Dim formatter As New Rss20FeedFormatter()
formatter.ReadFrom(RSSReader)
lblTitle.Text = formatter.Feed.Title.Text
lblDescription.Text = formatter.Feed.Description.Text
hlRss.NavigateUrl = formatter.Feed.Links(0).Uri.AbsoluteUri
lvRSS.DataSource = formatter.Feed.Items
lvRSS.DataBind()
Dim systime As DateTime
systime = DateTime.Today()
Response.Write(systime)
Dim connect As SqlConnection
Dim command As SqlCommand
Dim query As String
connect = New SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\admin\Documents\RssFeed.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True")
query = "insert into RSS values(@title,@link,@description)"
For Each Items As ListViewItem In lvRSS.Items
command = New SqlCommand(query, connect)
command.Parameters.AddWithValue("@title", formatter.Feed.Title.Text)
command.Parameters.AddWithValue("@link", formatter.Feed.Links(0).Uri.AbsoluteUri)
command.Parameters.AddWithValue("@description", formatter.Feed.Description.Text)
Next
connect.Open()
If command.ExecuteNonQuery() Then
lblmsg.Text = "save"
Else
lblmsg.Text = "not save"
End If
connect.Close()
End Sub
End Class