Results 1 to 2 of 2

Thread: Change sql query to XML

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2020
    Posts
    13

    Change sql query to XML

    Hi. Googling this gives me 30 different answers, and I'm just getting more confused. I have an existing application that displays appointments on a calendar, but it uses a database, and I want to change it to xml. I've created a dataset and datable using xml but can't figure out how to alter the following code to query xml instead of the database.

    Code:
     Public Function QueryAsDataTable(ByVal sql As String) As DataTable
            Dim da As New OleDbDataAdapter(sql, cn)
            Dim ds As New DataSet
            da.Fill(ds, "result")
            Return ds.Tables("result")
        End Function
    Code:
     Private Sub AddAppointmentToFlDay(ByVal startDayAtFlNumber As Integer)
            Dim startDate As DateTime = New Date(currentDate.Year, currentDate.Month, 1)
            Dim endDate As DateTime = startDate.AddMonths(1).AddDays(-1)
    
         
            Dim sql As String = $"select * from appointment where AppDate between #{startDate.ToShortDateString()}# and #{endDate.ToShortDateString()}#"
            Dim dt As DataTable = QueryAsDataTable(sql)
         
    
            For Each row As DataRow In dt.Rows
                Dim appDay As DateTime = DateTime.Parse(row("AppDate"))
                Dim link As New LinkLabel
                link.Tag = row("ID")
                link.Name = $"link{row("ID")}"
                link.Text = row("ContactName")
                AddHandler link.Click, AddressOf ShowAppointmentDetail
                listFlDay((appDay.Day - 1) + (startDayAtFlNumber - 1)).Controls.Add(link)
            Next
        End Sub
    that cn part was just the oledb connection. The calendar uses flowlayoutpanel to display the days in separate panels.
    Any help would be appreciated - Thanks

  2. #2
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    105,743

    Re: Change sql query to XML

    The DataSet and DataTable classes both have ReadXml and WriteXml methods so you can read and write directly to and from XML files. Once you have all the data in a DataTable, you can filter by calling Select on the DataTable, setting the RowFilter of the DefaultView or another DataView that you create or you can bind via a BindingSource and set the Filter property.

Posting Permissions

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



Click Here to Expand Forum to Full Width