Results 1 to 2 of 2

Thread: Getting latest date from RSS feed

  1. #1
    Acidtrash is offline VB.NET Forum Newbie
    .NET Framework
    .NET 3.5
    Join Date
    Jul 2012
    Posts
    5
    Reputation
    0

    Getting latest date from RSS feed

    I have some code (below). As you can see, I don't really know what I am doing. I've been hacking at bits of code that looks about right.
    The idea is that this routine retrives the location of an rss feed from my blogroll then loads it to scan it for the latest posting date, then update my database with the latest date.


    It does cycle through all the links in the recordset but the bit that is supposed to get the latest date, I dont think is anywhere near right.
    I think the "For Each objItem In objitems" is probably wrong and for some reason it underlines "thedate" in the update query and says I cant use it because Ive used it before it has been assigned a value, which presumably means the xml scan is not setting the variable to anything. But it says that before I even exectute so I really don't know. Any ideas?

    Thanks.


    PHP Code:

    Protected Sub Button2_Click(sender As ObjectAs System.EventArgsHandles 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 thedate As String
            Dim brid 
    As Integer
            Dim objXML 
    As Object

            connetionString 
    ConfigurationManager.ConnectionStrings("cerberusConnectionString").ConnectionString
            connection 
    = New SqlConnection(connetionString)
            
    connection.Open()
            
    command = New SqlCommand(SQLconnection)
            
    adapter.SelectCommand command
            adapter
    .Fill(ds)

            For 
    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 0Then
                    objRoot 
    objXML.documentElement
                    objitems 
    objRoot.getElementsByTagName("item")
                    For 
    Each objItem In objitems
                        On Error Resume Next
                        thedate 
    objItem.selectSingleNode("pubDate").Text
                    Next
                End 
    If

                
    objXML Nothing

                Using Conn 
    As New SqlConnection(ConfigurationManager.ConnectionStrings("cerberusConnectionString").ConnectionString)
                    
    Dim sql1 As String "update tbl_blogroll set Lupdate='" thedate "' where brid=" brid
                    Dim myCommand1 
    As New SqlCommand(sql1Conn)
                    
    myCommand1.ExecuteNonQuery()
                
    End Using
            Next i

            adapter
    .Dispose()
            
    command.Dispose()
            
    connection.Close()
            
    Response.Redirect("Default.aspx")

        
    End Sub 

  2. #2
    Dunfiddlin's Avatar
    Dunfiddlin is offline VB.NET Forum Master
    .NET Framework
    .NET 4.0
    Join Date
    Jun 2012
    Posts
    253
    Reputation
    31
    Nope. That's because the assignment of a value is included in an If loop so there's a possibility (at least as far as the IDE is concerned) that a null exception could occur. Just do ..

    Dim thedate As String = ""

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Harvest time tracking