locked
I need this code to be 2 records per news item. Right now, its only 1. RRS feed

  • Question

  • User-1269860422 posted

    I simply need it to pull my records, and for every 2, make it it's own entry into the xml at the writer.writeelementstring with a <br> in between.

    Any help would be appreciated. Thanks!

     

     Dim MyStamp As Date
            MyStamp = FileDateTime("C:\websites\xmlfile3.xml")
         
            If MyStamp.AddMinutes(15) < Now Then
    
                Dim settings As New XmlWriterSettings()
                settings.Indent = True
                settings.NewLineOnAttributes = True
                Using writer As XmlWriter = XmlWriter.Create("C:\websites\xmlfile3.xml", settings)
                    writer.WriteStartDocument()
                    writer.WriteStartElement("NewsCollection")
    
                    Dim snm As String = FormatDateTime(DateTimeOffset.Now.AddDays(-90).ToString, DateFormat.ShortDate)
                    Dim BusName As Object
                    Dim Description As Object
                    Dim ID As Object
    
                    Dim ConnString As String = WebConfigurationManager.ConnectionStrings("MembersAccessDatabase").ConnectionString
    
                    Dim SqlString As String = "SELECT * FROM Results WHERE ((MemberDate >= #" & snm & "#) AND (Member = 'Y') AND (NM = 'Y')) ORDER BY BusName ASC"
                                   Using conn As New OleDbConnection(ConnString)
                        Using cmd As New OleDbCommand(SqlString, conn)
                            cmd.CommandType = CommandType.Text
                            conn.Open()
                            Using reader As OleDbDataReader = cmd.ExecuteReader()
                                While reader.Read()
                                    ID = reader("ID")
                                    If Not reader("Description") Is DBNull.Value Then
                                        If Trim(reader("Description")) <> "NA" Then
                                            If reader("Description").ToString.Length > 126 Then
                                                Description = Left(reader("Description"), 125) & "..."
                                            Else
                                                Description = reader("Description")
                                            End If
    
                                        Else
                                            Description = "More info coming soon."
                                        End If
                                    Else
                                        Description = "More info coming soon."
                                    End If
                                    BusName = reader("BusName")
    
                                    writer.WriteElementString("News", "<a class=ColorLink2 href='member_dir.aspx?id=" & ID & "'><font face='verdana' size='1'>" & BusName & ":</a>  " & Description & "</font>")
                                End While
                            End Using
                        End Using
                    End Using
                    writer.WriteEndElement()
                    writer.WriteEndDocument()
                    writer.Flush()
                End Using
            End If
    Thursday, April 28, 2011 1:53 PM

All replies

  • User-1828494216 posted

    Before line Dim SqlString As String = "SELECT * add new variable

     

    Dim CurrCount as integer = 0

    then use IF statement after line writer.WriteElementString

     

    CurrCount += 1
    If CurrCount Mod 2 = 0 Then
        'insert br
    End If
    

    If u're looking for performance (speed) i would suggest you to look at XDocument class ;)

    Thursday, April 28, 2011 2:33 PM
  • User-1269860422 posted

    Thanks for your response, however, that will not make my news item contain 2 items from my database.  The writer.WriteElementString will somehow need to be changed to combine 2 records witha  break in between.

    Friday, April 29, 2011 8:36 AM
  • User-1828494216 posted

    Hi,

    i guess i did not understood you problem corectly... sorry...

    please post a sample of your Table and the sample of XML file u expect to get...

    Thanks.

    Friday, April 29, 2011 5:15 PM