473,847 Members | 1,432 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

"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.FileS tream(XMLFile,
System.IO.FileM ode.Open)

Dim XmlReader As New XmlTextReader(f sReadXml)

dsCodes.ReadXml (XmlReader)

XmlReader.Close ()
'fill the grid
DataGrid1.DataS ource = 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='Adress 1' 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 2156
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(dsCode s.Tables("Codes "))
dvCodes.Sort = "Name" ' * only if you wanted it sorted
dvCodes.RowFilt er = "Proj No = '" & strProj & "'"
DataGrid1.DataS ource = 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.FileS tream(XMLFile,
System.IO.FileM ode.Open)

Dim XmlReader As New XmlTextReader(f sReadXml)

dsCodes.ReadXml (XmlReader)

XmlReader.Close ()
'fill the grid
DataGrid1.DataS ource = 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='Adress 1' 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.Colu mnMapping &
DataRelation.Ne sted 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.TableNam e, "table")
Debug.Indent()
For Each column As DataColumn In table.Columns
Debug.WriteLine (column.ColumnN ame, "column")
Debug.Indent()
Debug.WriteLine (column.ColumnM apping, "mapping")
Debug.Unindent( )
Next
Debug.Unindent( )
Next
For Each relation As DataRelation In ds.Relations
Debug.WriteLine (relation.Relat ionName, "relation")
Debug.Indent()
Debug.WriteLine (relation.Neste d, "nested")
Debug.WriteLine (relation.Paren tTable, "parent")
Debug.Indent()
For Each column As DataColumn In relation.Parent Columns
Debug.WriteLine (column.ColumnN ame, "column")
Next
Debug.Unindent( )
Debug.WriteLine (relation.Child Table, "child")
Debug.Indent()
For Each column As DataColumn In relation.ChildC olumns
Debug.WriteLine (column.ColumnN ame, "column")
Next
Debug.Unindent( )
Debug.Unindent( )
Next
Hope this helps
Jay

"Cor" <no*@non.com> wrote in message
news:eS******** ******@TK2MSFTN GP09.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.248.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******** ******@TK2MSFTN GP10.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

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

Similar topics

0
1629
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 great... but don't nuke me for not hiring a private a2kX investigator to find it. If you are deploying the Runtime of any of these versions of Access you can get the right-click context menu to show the "Filter For: <textbox>" option by doing the...
4
1916
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 web user control which uses some Atlas functionality; The web user control contains a "DataList" which gets updated asynchronously through Atlas when the user clicks a button –the button is the Atlas trigger.
0
1991
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
2902
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 where there is a NULL value in that field get eliminated. Without getting crazy (i.e. designing your own bottons and "re- inventing the wheel"), is there a way to make Access stop doing this?
1
6066
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 a form that have the same effect as the "Filter by Form", "Apply Filter" and "Remove Filter" Buttons on the access toolbar. Help would be muchly appreciated. Cheers. In the Click() Event of 3 Command Buttons, place the following code: Code: (...
2
6442
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 contain a null value. Its just the same as if I want to show all records with null values. Any ideas?
1
2283
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 List values; OPEN, CLOSED
6
1612
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 the client host address, and the other is the user name provided as for Basic Authentication (http://user@www.bla-bla.com). To do this, at the present I've overwritten the do_POST method of SimpleXMLRPCRequestHandler, including at a certain...
0
1782
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 "Search2000": http://allenbrowne.com/ser-62.html Now, I'd like to have an option in the main form to hide the entries in the subform that I consider duplicates (entries with same
0
9889
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9732
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10988
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10652
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10344
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7886
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7058
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4536
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4126
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.