Zooming Out: The Larger Issue (A Question for Experts)

P

Peter

The more questions I ask, the more likely I'll ask the right one and someone
will answer it, right?

Here's the big picture on my project: I'm writing a program that will keep
track of, among other things, paper inventory. I want there to be a master
list of available paper colors on a form that users can choose from, each
one having a name and a color box. The colors would be grouped into
categories; i.e. brands etc. I also want there to be a way for users to add
and delete colors and groups from the master list. I therefore envisioned
having a simple XML file with the paper colors stored in it that the program
referenced each time it wanted to build this control. The XML file would
have the general structure:

<AllPaperColors>
<PaperColorSet name="Pastels">
<PaperColor color="ff928a" name="Cherry"></PaperColor>
<PaperColor color="ad4325" name="Azure"></PaperColor>
<PaperColor color="423441" name="Orchid"></PaperColor>
<PaperColor color="000997" name="Peach"></PaperColor>
</PaperColorSet>
<PaperColorSet name="Astrobrights">
<PaperColor color="aaeeff" name="Ice"></PaperColor>
<PaperColor color="ff0099" name="Magenta"></PaperColor>
<PaperColor color="ff5600" name="Chartreuse"></PaperColor>
<PaperColor color="0099ff" name="Aqua"></PaperColor>
</PaperColorSet>
</AllPaperColors>

This XML file seemed like the most elegant and supremely simple of all
possible solutions... quite aside from the fact that I don't know what SQL
Server is, and it sounds like it costs money, extra hardware, and months to
learn, none of which I am willing to invest at this point.

Not knowing at all how to approach reading a file structured like this, I
decided to use a DataSet object... it allows both reading and writing in
non-sequential order. I wrote an XML schema to match the above file and
applied it to the DataSet, even though it seemed to work ok without doing
so. I still don't know what the benefit of that was, other than that now I
can click "Validate XML" and no errors come up.

Now I'm having problems accessing nested elements in the bizarre structure
of the DataSet object. I don't know what properties and methods to use to
get it to do what I want. Several of them have similar descriptions that I
can't tell apart. For example, I notice that there is a Tables collection,
but there is also a PaperColorSet property. What the heck is that? Which one
contains the data? And the Rows collection... what's the difference between
Rows(0) and Rows.Item(0)? Why does neither one have a ToString property? I
have a lot of questions like that. Add that to the nested tables confusion I
already mentioned in a previous post.

So my question to you genius VB developers out there is this: have I taken a
bizarre or non-standard approach to a really simple problem? Is there any
step in the process I described above (including the structure of the XML
file, or the choice to use XML at all) that is unquestionably inferior? I'm
groping in the dark, and every tiny step is a bloody battle.

If I have done ok so far, are there any resources I could read now to learn
what tables really are? And how XML elements containing attributes, content,
and other elements are translated into tables, rows, and columns? It's an
odd way for me to conceptualize representing such simple data, and the
graphical XML designer is only adding to my confusion at this point. Not too
much longer, and I may go off the deep end and try to write an XML parser
from the ground up -- one I can understand!

Any thoughtful help is much appreciated.
 
M

Michel Posseth [MCP]

Well i personally would have chosen a different aproach

I would have set up a dataset with the desired interface with the dataset
designer , and then bind my controls to this dataset

Then you can add colors with the bound controls and save the dataset to a
XML file or a binary file ( smaller and faster to serialize deserialize ,
however you can`t add items then with notepad )

On startup of your app you could just check if the xml / binary file exists
and if so desiaralize it to a dataset object and rebind it to your controls

The above requires verry few coding ( it is 80% draging and dropping )

you may also choose to do it all from code
to get you started with this
http://www.startvbdotnet.com/ado/datatable.aspx


dataset = the container of one or more datatables

datatable = the container of one or more datarows

datarow = the container of one or more datacolumns wich in there turn hold
the values ( it ends there :)

so in simplified XML it looks like this

1 dataset with 1 datable 1 datarow and 1 datacolumn

<dataset>
<datatable>
<datarow>
<datacolumn>
this is the value of colun 1
</datacolumn>
</datarow>
</datatable>
</dataset>


So if you refer in code to datatable(0) you get all items that are nested in
the first datatable object even so with the rows and columns

This represents a pseudo dataset with 1 datatable , 2 datarows and 3 data
columns

<dataset>
<datatable>
<datarow>
<datacolumn>
1
</datacolumn>
<datacolumn>
2
</datacolumn>
<datacolumn>
3
</datacolumn>
</datarow>
<datarow>
<datacolumn>
4
</datacolumn>
<datacolumn>
5
</datacolumn>
<datacolumn>
6
</datacolumn>
</datarow>
</datatable>
</dataset>

If you want a good reference about datasets i would recomend you one of the
ADO.Net books of MS press (i own the advanced topics book wich is verry
good )

regards

Michel Posseth [MCP]
 
S

sloan

http://sholliday.spaces.live.com/blog/


If you're starting from scratch, then I'd create a strongly typed dataset
first.
This will make life easier on you.
Your xml below isn't bad, but its not as "dataset-ish" as it ought to be.

After you create a strong dataset, you can manually add rows to you.

Then you can do a myDS.Write( @"C:\myfile.xml") and see the output.

This is a better direction of approach then the other way.


5/24/2006
Custom Objects/Collections and Tiered Development


If you download my example, you can do something like this:


CustomerOrderInfoDSNoConstraintsDS myds = new
CustomerOrderInfoDSNoConstraintsDS();

myds.Customer.AddNewCustomerRow ( "111" , "John" , "Boise" ) ;
myds.Customer.AddNewCustomerRow ( "222" , "Mary" , "Winchester");

myds.Order.AddNewOrderRow( 1001 , "111" , DateTime.Now , DateTime.Now ,
1.00 ) ; //you may have to adjust a little
myds.Order.AddNewOrderRow( 2002 , "222" , DateTime.Now , DateTime.Now ,
2.00 ) ;//you may have to adjust a little

myds.Write ( @"C:\myfirststrongdsfile.xml" ) ;


That should get you going.

DataSet xml is largely ~element based. Your xml above is largely ~attribute
based.

Doing the above example will show you the difference.
 
P

Peter

Well i personally would have chosen a different aproach
I would have set up a dataset with the desired interface with the dataset
designer , and then bind my controls to this dataset

Then you can add colors with the bound controls and save the dataset to a
XML file or a binary file ( smaller and faster to serialize deserialize ,
however you can`t add items then with notepad )

On startup of your app you could just check if the xml / binary file
exists and if so desiaralize it to a dataset object and rebind it to your
controls

Thank you for the idea. I think I am going to try to pursue a course of
action similar to this.
 
P

Peter

If you're starting from scratch, then I'd create a strongly typed dataset
first.
This will make life easier on you.
Your xml below isn't bad, but its not as "dataset-ish" as it ought to be. ....
DataSet xml is largely ~element based. Your xml above is largely
~attribute
based.

Thank you for the distinction. I designed the XML structure by hand before
going into VB, doing what seemed to make the most sense semantically... i.e.
the Name of a PaperColor element seemed more like an attribute than a child
element... but you're right; it makes the dataset a lot more cryptic to work
with. Thanks for the help.
 

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

Similar Threads


Top