473,383 Members | 1,829 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

"Filter" data from XML datafile into datagrid

Hi,

I fill a datgrid with data from a xml document, it works fine
But....
Now I will to filter the data to the grid so only the data shows from
the criteria that I set.

My code now is very simple to fill the grid

Dim strProj As String

Dim MyA As String()
Dim dsCodes As New DataSet
Dim fsReadXml As New System.IO.FileStream(XMLFile,
System.IO.FileMode.Open)

Dim XmlReader As New XmlTextReader(fsReadXml)

dsCodes.ReadXml(XmlReader)

XmlReader.Close()
'fill the grid
DataGrid1.DataSource = dsCodes.Tables(XMLTable)
I wont to show all customerdata for my customer in my grid there only
Proj No = strProj

My XML file looks like this:

<?xml version='1.0' encoding='utf-8' ?>
<!--Code Information-->
<xml>
<projectinfo>
<Cust No='2298' Name='Company1' Adress1='Adress1' Adress2
='Box 999'
Adress3='161 02 BROMMA' Phone='08-999 91 90' Fax=''
Trakt='0' />
<Proj No='445640' Name='Ongoing' />
</projectinfo>
<projectinfo>
<Cust No='2324' Name='Company2' Adress1='xxxxx' Adress2='Box
230'
Adress3='127 24 HOLMEN' Phone='08-999 99 00' Fax=''
Trakt='0' />
<Proj No='232401' Name='Ongoing' />
<Proj No='232402' Name='Test' />
<Proj No='232403' Name='Startup' />

</projectinfo>
</xml>
I have search for this but I couldnt find anything about it, maybe
someone has got an solution or a tips there I could find it.

//Regards Thomas
Nov 20 '05 #1
11 2109
You have to use a DataView because only a DataView has the capability to
filter data or sort it. So, you'll need to do something like this:

dvCodes = New DataView(dsCodes.Tables("Codes"))
dvCodes.Sort = "Name" ' * only if you wanted it sorted
dvCodes.RowFilter = "Proj No = '" & strProj & "'"
DataGrid1.DataSource = dvCodes

and just assign the DataView to the datagrid instead of the DataSet.
Thomas A wrote:
Hi,

I fill a datgrid with data from a xml document, it works fine
But....
Now I will to filter the data to the grid so only the data shows from
the criteria that I set.

My code now is very simple to fill the grid

Dim strProj As String

Dim MyA As String()
Dim dsCodes As New DataSet
Dim fsReadXml As New System.IO.FileStream(XMLFile,
System.IO.FileMode.Open)

Dim XmlReader As New XmlTextReader(fsReadXml)

dsCodes.ReadXml(XmlReader)

XmlReader.Close()
'fill the grid
DataGrid1.DataSource = dsCodes.Tables(XMLTable)
I wont to show all customerdata for my customer in my grid there only
Proj No = strProj

My XML file looks like this:

<?xml version='1.0' encoding='utf-8' ?>
<!--Code Information-->
<xml>
<projectinfo>
<Cust No='2298' Name='Company1' Adress1='Adress1' Adress2
='Box 999'
Adress3='161 02 BROMMA' Phone='08-999 91 90' Fax=''
Trakt='0' />
<Proj No='445640' Name='Ongoing' />
</projectinfo>
<projectinfo>
<Cust No='2324' Name='Company2' Adress1='xxxxx' Adress2='Box
230'
Adress3='127 24 HOLMEN' Phone='08-999 99 00' Fax=''
Trakt='0' />
<Proj No='232401' Name='Ongoing' />
<Proj No='232402' Name='Test' />
<Proj No='232403' Name='Startup' />

</projectinfo>
</xml>
I have search for this but I couldnt find anything about it, maybe
someone has got an solution or a tips there I could find it.

//Regards Thomas

Nov 20 '05 #2
Cor
Hi Copyco,

The problem is that the used XML file is not a dataset but a XML file
(wellformed).
(It has 3 tables but I cannot find a way to make a relation with it in a
dataset way).
As far as I see it now, is making a nice datatable from it the best, but I
am waiting if we see a better answer also.

When I see the code than I asume Thomas is not a real expirienced one with
dataset, datatables etc. and therefore I do not know what is the best
answer.

(Maybe it is better if he starts to make a dataset XML file instead of a XML
file)
Cor
Nov 20 '05 #3
Cor,
When I see the code than I asume Thomas is not a real expirienced one with
dataset, datatables etc. and therefore I do not know what is the best
answer. Huh?

I hope you realize that using the DataColumn.ColumnMapping &
DataRelation.Nested properties a DataSet can create the XML that Thomas
showed!

If any thing Thomas is using the DataSet in a very advanced method, which in
some cases is preferred.
(It has 3 tables but I cannot find a way to make a relation with it in a
dataset way).
Remember when the DataSet reads the XML it will automatically define (infer)
the relationship.

Try the following code after Thomas's code to see the above settings in
action.

For Each table As DataTable In ds.Tables
Debug.WriteLine(table.TableName, "table")
Debug.Indent()
For Each column As DataColumn In table.Columns
Debug.WriteLine(column.ColumnName, "column")
Debug.Indent()
Debug.WriteLine(column.ColumnMapping, "mapping")
Debug.Unindent()
Next
Debug.Unindent()
Next
For Each relation As DataRelation In ds.Relations
Debug.WriteLine(relation.RelationName, "relation")
Debug.Indent()
Debug.WriteLine(relation.Nested, "nested")
Debug.WriteLine(relation.ParentTable, "parent")
Debug.Indent()
For Each column As DataColumn In relation.ParentColumns
Debug.WriteLine(column.ColumnName, "column")
Next
Debug.Unindent()
Debug.WriteLine(relation.ChildTable, "child")
Debug.Indent()
For Each column As DataColumn In relation.ChildColumns
Debug.WriteLine(column.ColumnName, "column")
Next
Debug.Unindent()
Debug.Unindent()
Next
Hope this helps
Jay

"Cor" <no*@non.com> wrote in message
news:eS**************@TK2MSFTNGP09.phx.gbl... Hi Copyco,

The problem is that the used XML file is not a dataset but a XML file
(wellformed).
(It has 3 tables but I cannot find a way to make a relation with it in a
dataset way).
As far as I see it now, is making a nice datatable from it the best, but I
am waiting if we see a better answer also.

When I see the code than I asume Thomas is not a real expirienced one with
dataset, datatables etc. and therefore I do not know what is the best
answer.

(Maybe it is better if he starts to make a dataset XML file instead of a XML file)
Cor

Nov 20 '05 #4
Thank you all,

It works fine now.

I think also that I should make two xml files instead of one
One with customer data and one with project info.

is it possible to link 2 xml files with data to one datagrid
I thininking about a query to show projectnumber, projectname from
project.xml and customername from customer.xml linked by customercode
from both files.

//Thomas
Nov 20 '05 #5
Thomas,
You can use the Merge method to merge two DataSets into a single Dataset.

After you loaded each XML file into their own DataSet.

Then you might be able to use the JoinView sample custom DataView class for
VB.NET to join the project data with the customer data.

See:
http://support.microsoft.com/default...en-us%3B325682

Basically you create a new JoinView object, set the properties for your
join, then use this JoinView object as the DataSource on your DataGrid.

Hope this helps
Jay

"Thomas A" <th**************@msn.com> wrote in message
news:Xn**********************************@207.46.2 48.16...
Thank you all,

It works fine now.

I think also that I should make two xml files instead of one
One with customer data and one with project info.

is it possible to link 2 xml files with data to one datagrid
I thininking about a query to show projectnumber, projectname from
project.xml and customername from customer.xml linked by customercode
from both files.

//Thomas

Nov 20 '05 #6
Cor
Hi Jay B.

Are you sure of that all.

I hope that you know that it is much easier to test this using the VS.net
tools.

Just paste the XML file from Thomas on an empty item XML file that you have
opened in the IDE.

Than just right click and say create schema.
An XSD file is formed. And right away you have an error on your XML file,
because the schema correspondent not with the XML file.

When you look at the schema, than you will see that there is no relation at
all between the project information and the customer information.

However, I think that when the XML reader (not the dataset) is used to
create a new datatable, the new datatable can be used to represent that in
the datagrid with selecting. (Without updating of course to the XML file
back).

Because of the last fact I think it is better when Thomas creates a real
dataset with posible relations between the customer and the projectinfo.

As I said in my earlier post maybe is it possible to create a relation to
the parent projectinfo from the Proj and than try to get the first childrow
from the related Cust table, but I think that it will be a lot of work to
find out how. In addition, this will than only work because the logic exist
in this situation that there is only one customer row in a projectinfo. For
this I think it will also not possible to update.

I hope this helps?

Cor


Nov 20 '05 #7
Cor
Hi Thomas,

If you make one or two XML files is not that important I think.
(I think it is not a bad idea).

But the main thing is that you have situated your customer info in your
projectinfo and that is bad design.

You have customers and for those you have projects.

A project is related to a customer and has therefore the id from the
customer has to be in the data of a project (Before you write it, no that
would not be necessary with XML file but it is for a dataset).

And also make from all what is now an attribute an element, that is what the
dataset also does.

Cor

Nov 20 '05 #8
Cor,
Are you sure of that all. Of course I'm sure!

You should realize by now that rarely do I say anything that I am not sure
about. Or that I am not able or willing to back up.
I hope that you know that it is much easier to test this using the VS.net
tools. I hope that you realize that the VS.NET tools are just that, they are tools,
designed to give you X, while the DataSet gives you X & Y.

All you have succeeded in doing is prove that the VS.NET tools do not fully
support Y at the level that the DataSet does. HOWEVER!
Than just right click and say create schema.
An XSD file is formed. And right away you have an error on your XML file,
because the schema correspondent not with the XML file. I'm not seeing an error (in VS.NET 2003).
As I said in my earlier post maybe is it possible to create a relation to Obviously you missed the part in my post that stated that the DataSet
already does!

Hope this helps
Jay

"Cor" <no*@non.com> wrote in message
news:un**************@TK2MSFTNGP10.phx.gbl... Hi Jay B.

Are you sure of that all.

I hope that you know that it is much easier to test this using the VS.net
tools.

Just paste the XML file from Thomas on an empty item XML file that you have opened in the IDE.

Than just right click and say create schema.
An XSD file is formed. And right away you have an error on your XML file,
because the schema correspondent not with the XML file.

When you look at the schema, than you will see that there is no relation at all between the project information and the customer information.

However, I think that when the XML reader (not the dataset) is used to
create a new datatable, the new datatable can be used to represent that in
the datagrid with selecting. (Without updating of course to the XML file
back).

Because of the last fact I think it is better when Thomas creates a real
dataset with posible relations between the customer and the projectinfo.

As I said in my earlier post maybe is it possible to create a relation to
the parent projectinfo from the Proj and than try to get the first childrow from the related Cust table, but I think that it will be a lot of work to
find out how. In addition, this will than only work because the logic exist in this situation that there is only one customer row in a projectinfo. For this I think it will also not possible to update.

I hope this helps?

Cor

Nov 20 '05 #9
Cor
Hi Jayb B,
I hope that you know that it is much easier to test this using the VS.net
tools.
You should realize by now that rarely do I say anything that I am not sure
about. Or that I am not able or willing to back up.
You should realize that with me is the same and that I do not like this kind
of statements to my adres. (But maybe you have a MVP status that gives you
the right to do that and I do not have that).
Obviously you missed the part in my post that stated that the DataSet
already does!

Than show it, because I will really like to see how you can make from two
almost nonrelated datatables on a equal a level a relation. Your debugging
using a XML file read is absolutly not importang in this. XML has a lot of
ways to use and they are not all mixable.

As I already stated this whole thread is in my opinion the XML file from
Thomas no dataset.

I will gladly see a dataset made with complex elements and in that
attributes.

Cor
Nov 20 '05 #10
Cor,
Than show it, because I will really like to see how you can make from two
almost nonrelated datatables on a equal a level a relation.
Run the previously posted code (copied here for you convenience):

Dim strProj As String

Dim MyA As String()
Dim dsCodes As New DataSet
Dim fsReadXml As New System.IO.FileStream(XMLFile,
System.IO.FileMode.Open)

Dim XmlReader As New XmlTextReader(fsReadXml)

dsCodes.ReadXml(XmlReader)

XmlReader.Close()

For Each table As DataTable In ds.Tables
Debug.WriteLine(table.TableName, "table")
Debug.Indent()
For Each column As DataColumn In table.Columns
Debug.WriteLine(column.ColumnName, "column")
Debug.Indent()
Debug.WriteLine(column.ColumnMapping, "mapping")
Debug.Unindent()
Next
Debug.Unindent()
Next
For Each relation As DataRelation In ds.Relations
Debug.WriteLine(relation.RelationName, "relation")
Debug.Indent()
Debug.WriteLine(relation.Nested, "nested")
Debug.WriteLine(relation.ParentTable, "parent")
Debug.Indent()
For Each column As DataColumn In relation.ParentColumns
Debug.WriteLine(column.ColumnName, "column")
Next
Debug.Unindent()
Debug.WriteLine(relation.ChildTable, "child")
Debug.Indent()
For Each column As DataColumn In relation.ChildColumns
Debug.WriteLine(column.ColumnName, "column")
Next
Debug.Unindent()
Debug.Unindent()
Next

'fill the grid
DataGrid1.DataSource = dsCodes.Tables(XMLTable)

Or are you asking how to create said DataSet, either from a XSD or via code?

Your debugging
using a XML file read is absolutly not importang in this. XML has a lot of
ways to use and they are not all mixable. The Debug.Writelines are showing you how the DataColumn.ColumnMapping &
DataRelation.Nested work to give you what Thomas is asking for, how are they
not important?

In other words: why state "then show it" then immediately dismiss the
example where I do show it???

Note: If you want a response to the other "static" send me a private email.

Hope this helps
Jay

"Cor" <no*@non.com> wrote in message
news:ej**************@TK2MSFTNGP09.phx.gbl... Hi Jayb B,
I hope that you know that it is much easier to test this using the VS.nettools.
You should realize by now that rarely do I say anything that I am not
sure about. Or that I am not able or willing to back up.


You should realize that with me is the same and that I do not like this

kind of statements to my adres. (But maybe you have a MVP status that gives you
the right to do that and I do not have that).
Obviously you missed the part in my post that stated that the DataSet
already does!
Than show it, because I will really like to see how you can make from two
almost nonrelated datatables on a equal a level a relation. Your

debugging using a XML file read is absolutly not importang in this. XML has a lot of
ways to use and they are not all mixable.

As I already stated this whole thread is in my opinion the XML file from
Thomas no dataset.

I will gladly see a dataset made with complex elements and in that
attributes.

Cor

Nov 20 '05 #11
Cor
Hi JaybB,

Thank you for your message.

I send you a seperate mail for the other situation.

This is what I all the time try to tell to you and also have described in my
last message.

This is the printed relation from the given XML file with your sample (only
the last part the first is for this not important in my eyes, from that I
have an XSD schema).
relation: projectinfo_Cust
nested: True
parent: projectinfo
column: projectinfo_Id
child: Cust
column: projectinfo_Id
relation: projectinfo_Proj
nested: True
parent: projectinfo
column: projectinfo_Id
child: Proj
column: projectinfo_Id
I have extended your code with this.
\\\
For Each table As DataTable In ds.Tables
Debug.WriteLine(table.TableName, "table")
Debug.Indent()
For Each row As DataRow In table.Rows
Debug.WriteLine(row("projectinfo_Id"), "id")
Next
Debug.Unindent()
Next
///
Than I get this.
table: projectinfo
id: 0
id: 1
table: Cust
id: 0
id: 1
table: Proj
id: 0
id: 1
id: 1
id: 1

Exactly as I said some messages before in this thread
-----------------------------
As I said in my earlier post maybe is it possible to create a relation to
the parent projectinfo from the Proj and than try to get the first childrow
from the related Cust table, but I think that it will be a lot of work to
find out how. In addition, this will than only work because the logic exist
in this situation that there is only one customer row in a projectinfo. For
this I think it will also not possible to update.
------------------------------
By the way, do you know that in the code from Thomas only this is needed.

Dim ds As New DataSet
ds.ReadXml("c:\testx.xml")
DataGrid1.DataSource = ds.Tables(0)

Cor

Nov 20 '05 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Jerry Boone | last post by:
I did a lot of searching and found many who said this couldn't be done. After searching I didn't "seem" to turn up anyone who provides this solution. If you posted or found something on this...
4
by: Jeeran | last post by:
We use an ISAPI filter to convert long urls into short clean ones. For example: "Site.com/user/john/" Is re-written as: "Site.com/user/userinfo.aspx?uid=john" Now, "userinfo.aspx" contains a...
0
by: gpl666666 | last post by:
I use access to make a "page", below the page form, there are "filter by selection" and "filter toggle button" what are these two bottons for?
2
by: ManningFan | last post by:
Go into a table where you have a field that has NULL values. Right- Click on a record with a value in that field and choose "Filter Excluding Selection". Some (or most, or all) of your records...
1
by: mattscho | last post by:
Re: Filter By From, Apply Filter, Remove Filter Buttons in a Form. -------------------------------------------------------------------------------- Hi All, Trying to create a set of 3 buttons in...
2
nev
by: nev | last post by:
Does anyone know how to do that? In my real project actually, I filter on two fields like this... bindingsource.filter = "col1='" & var1 & "' AND col2='" & var2 & "'" wherein var1 or var2 may...
1
gcoaster
by: gcoaster | last post by:
Hello, Access is accessing my patience! how does one filter just one form with a single combo box selection? I have a combo box named "cboCallStatus" unbound Row source type = Value...
6
by: Luigi | last post by:
Dear all, I'm writing an XML-RPC server which should be able to modify the incoming request before dispatching it. In particular I wand to added two fixed parameters to the method called: one is...
0
by: Ornitobase | last post by:
Hello, my form is used to filter data displayed in its subform. The origin of the data of the subform is dynamically generated. The filters work in VBA. The code is inspired by Allen Browne's...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.