Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Recordsets 1

Status
Not open for further replies.

RonRepp

Technical User
Feb 25, 2005
1,031
US
Hi all:

I have posted a simlar question, but apparently nobody can answer.

Question: How do you turn an XML recordset into a SQL type recordset?

I'm using a dataset and datagrid, and here is the code:

Code:
Private DS As DataSet = New DataSet("DS")
    Private TBL As DataTable = New DataTable("TBL")
    Private xFile As String = "C:\d4d_485_OrderList.xml"


    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        DS.ReadXml(xFile)
        Me.DataGrid1.DataSource = DS

    End Sub

    Private Sub bConvert_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bConvert.Click
        Dim i, j As Int16
        For i = 0 To DS.Tables.Count - 1
            TBL = DS.Tables(i)
            For j = 0 To TBL.Columns.Count - 1
                MsgBox(TBL.TableName & vbCrLf & TBL.Columns(j).ColumnName)
            Next
        Next
    End Sub

Any help will be greatly appreciated.

Ron Repp

If gray hair is a sign of wisdom, then I'm a genius.
 
Ron..
this seems to be a case of you have read an xml file into the dataset without a xsl file...

The lack of the xsl (XML Schema file) causes the xml to load untyped data..

What I have done in the past that seem to parallel your scenario, is load a dataset from a sql query.

Then use the datasets.WriteXmlSchema Method to create the xsl file..

At that point when I load the dataset from the xml file, I use the xsl file to create a typed dataset.

you do this with the datasets .ReadXmlSchema method.

HTH


Rob
 
Rob:

True: I have picked up an xml file off an FTP site and need to parse it like a SQL query.

What I'm trying to do is get one recordset, but I'd settle for just being able to iterate through the datatables, create text files, and then join them together later.

I'll check into the xsl file.

Thanks,

Ron Repp

If gray hair is a sign of wisdom, then I'm a genius.
 
Ahhhh..

Well the dataset that you populated can contain one or more recordsets (datatables)

Each of those Datatables can be filtered/sorted using a DataView Object. (Each datatable can have one or more dataviews)

The trick to iterating through a Dataset is that you will need 3 loops..

1 loop for the datasets.datatable collection
1 loop to loop through the datatables datarows collection
and
1 loop for the columns..

At that point every datatable can be "cloned" you can add rows to it via code..
e.g.
Dim r as datarow = datatable.newrow()
r.items(0).value='some val'
datatable.rows.add r
(from memory and might be a bit off)

You can also create adhoc datatables, define their columns, add rows to them and then add them to the dataset. (or a new dataset) - pros and cons.. Old Dataset means you get new and old tables when you save to xml, vrs new Dataset=just the tables you added to it.

If you want some code of looping through a dataset, applying a dataview etc.. Post Back and I will see what I can dig out.


Rob

 
NCH:

Thanks. I'll give it a try and post back.

Ron Repp

If gray hair is a sign of wisdom, then I'm a genius.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top