I have a piece of cose that cycles through a table of RSS file locations for blogs, opens up each file in an xml reader and then cycles through the items to get the date of the latest post - then fire that date into my databse to create a dynamic blogroll.
There are a couple of problems with this piece of code in that it cycles through all items which isn't needed. I just need it to get the first pubdate from the RSS file. I am using "For Each objItem In objitems" when I just want the first item. I don't know how to phrase this.
The second problem is that the sql insert doesn't seem to like my date variable due to conversion problems. I'm not too hot with those sorts of problems. Would be very grateful for any hints.
There are a couple of problems with this piece of code in that it cycles through all items which isn't needed. I just need it to get the first pubdate from the RSS file. I am using "For Each objItem In objitems" when I just want the first item. I don't know how to phrase this.
The second problem is that the sql insert doesn't seem to like my date variable due to conversion problems. I'm not too hot with those sorts of problems. Would be very grateful for any hints.
PHP:
Protected Sub Button2_Click(sender As Object, e As System.EventArgs) Handles Button2.Click
Dim connetionString As String
Dim connection As SqlConnection
Dim command As SqlCommand
Dim adapter As New SqlDataAdapter
Dim ds As New DataSet
Dim i As Integer
Dim cellcount As Integer
Dim objRoot As Object
Dim objitems As Object
Dim SQL As String = "select * from tbl_blogroll where rssloc is not null"
Dim brid As Integer
Dim objXML As Object
connetionString = ConfigurationManager.ConnectionStrings("cerberusConnectionString").ConnectionString
connection = New SqlConnection(connetionString)
connection.Open()
command = New SqlCommand(SQL, connection)
adapter.SelectCommand = command
adapter.Fill(ds)
For i = 0 To ds.Tables(0).Rows.Count - 1
Dim rss As String = ds.Tables(0).Rows(i).Item(3)
Dim thefeed As String = rss
brid = ds.Tables(0).Rows(i).Item(0)
objXML = Server.CreateObject("MSXML2.DOMDocument.4.0")
objXML = Server.CreateObject("Microsoft.XMLDOM")
objXML.Async = False
objXML.SetProperty("ServerHTTPRequest", True)
objXML.ResolveExternals = True
objXML.ValidateOnParse = True
objXML.Load(thefeed)
cellcount = 0
If (objXML.parseError.errorCode = 0) Then
objRoot = objXML.documentElement
objitems = objRoot.getElementsByTagName("item")
For Each objItem In objitems
Using Conn As New SqlConnection(ConfigurationManager.ConnectionStrings("cerberusConnectionString").ConnectionString)
Dim thedate As String = objItem.selectSingleNode("pubDate").Text
Dim sql1 As String = "update tbl_blogroll set Lupdate='" + thedate + "' where brid=" + brid
Dim myCommand1 As New SqlCommand(sql1, Conn)
myCommand1.ExecuteNonQuery()
End Using
Next
End If
objXML = Nothing
Next i
adapter.Dispose()
command.Dispose()
connection.Close()
Response.Redirect("Default.aspx")
End Sub