retrieve single values from typed DataSet - need help

T

Thomas

Hi,

I used xsd.exe to generate a *.xsd file from the *.xml-File and then I
created a typed DataSet in VisualStudio 2003

But now I have problems to read the data from the DataSet.

<?xml version="1.0" encoding="UTF-8"?>
<Message id="100199" version="1.9" something="1">
<Jobs id="999" priority="0">
<DataContainer generationDate="19042005102504" RecordCount="1">
<CardRecord number="123456" number_id="00000099" crnSeq="1"
Perso="1000000000000123456">
<Module mic="modul_1">
<Data name="name" format="TEXT">Mustermann</Data>
</Module>
<Module mic="modul_2">
<Data name="boss" format="TEXT">Maier</Data>
</Module>
<Module mic="modul_3">
<Data name="chef" format="TEXT">Hauser</Data>
</Module>
</CardRecord>
</DataContainer>
</Jobs>
</Message>


I like to read the values from "Data". I am able to show all of these
data with the following code:


foreach (DataRow custRow in newDataSet1.Tables["Data"].Rows)
{
this.listBox1.Items.Add(custRow.ItemArray[2]);
}

But I need to read single data. I want only show the part of the
Data-table that belongs to "modul_1" or "modul_2".

Is my idea with "ItemArray" good? I believe that there is a better way
to retrieve the data but I was not able to find it.


Thanks for all tips.


Gruß
Thomas
 
N

Nicholas Paldino [.NET/C# MVP]

Thomas,

It would seem that you want to populate the list. Have you thought
about using DataBinding (through the DataSource and DisplayMember properties
on the ListBox)? This will prevent you from having to write looping code
like that.

Also, if you only want to show rows that meet a certain criteria, you
can use a DataView on the table with the rows, setting the Filter property
to the correct filter. Then, you can bind to the DataView.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Hi,

I used xsd.exe to generate a *.xsd file from the *.xml-File and then I
created a typed DataSet in VisualStudio 2003

But now I have problems to read the data from the DataSet.

<?xml version="1.0" encoding="UTF-8"?>
<Message id="100199" version="1.9" something="1">
<Jobs id="999" priority="0">
<DataContainer generationDate="19042005102504" RecordCount="1">
<CardRecord number="123456" number_id="00000099" crnSeq="1"
Perso="1000000000000123456">
<Module mic="modul_1">
<Data name="name" format="TEXT">Mustermann</Data>
</Module>
<Module mic="modul_2">
<Data name="boss" format="TEXT">Maier</Data>
</Module>
<Module mic="modul_3">
<Data name="chef" format="TEXT">Hauser</Data>
</Module>
</CardRecord>
</DataContainer>
</Jobs>
</Message>


I like to read the values from "Data". I am able to show all of these
data with the following code:


foreach (DataRow custRow in newDataSet1.Tables["Data"].Rows)
{
this.listBox1.Items.Add(custRow.ItemArray[2]);
}

But I need to read single data. I want only show the part of the
Data-table that belongs to "modul_1" or "modul_2".

Is my idea with "ItemArray" good? I believe that there is a better way
to retrieve the data but I was not able to find it.


Thanks for all tips.


Gruß
Thomas
 
T

Thomas

Hi Nicholas,

thanks for your answer.

Thomas,

It would seem that you want to populate the list. Have you thought
about using DataBinding (through the DataSource and DisplayMember properties
on the ListBox)? This will prevent you from having to write looping code
like that.

the ListBox is only for Debug. Later I will use the retrieved data in a
different way. So I do not need data bindings at the moment.
My inention for this little demo-programm is to write the three "items"
(Mustermann, Maier, Hauser) to three different strings.
Also, if you only want to show rows that meet a certain criteria, you
can use a DataView on the table with the rows, setting the Filter property
to the correct filter. Then, you can bind to the DataView.

I also tried to use a DataView but I was not able to set the filter
correct.
I think that I need some detailed help. I am trying different things
for hours now but I am not able to get a result :-(


Sincerely
Thomas
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top