C# Dataset XML schema how do you define an Array?


I have a Dataset and an element in the table that I want to make into an array.

I created an Dataset called dsInventory, with a table called Inventory in the dataset designer in C#.

<xs:element name="PictureURL" type="xs:string" minOccurs="0" />

How do I make this an array? Setting maxOccurs to anything results in it not showing up and not being able to access it like this:

dsInventory.InventoryRow dr; (this is not really correct but just for illustration)
dr.PictureURL = "test";

What i'd like is to be able to do this:

dr.PictureURL[0] = "test0";
dr.PictureURL[1] = "test1";
dr.PictureURL[2] = "test2";
dr.PictureURL[3] = "test3";

StingethAsked:
Who is Participating?
 
gregasmConnect With a Mentor Commented:
picture URLs table would be able to support the concept of multiple elements as rows. That's a good choice.

You can also store an xml string in a single column of a row, and then parse it out. This is the case a lot of times in certain scenarios where the table has to be flexible enough to store nested tables. another column would store metadata that describes the nested table...

0
 
gregasmCommented:
you may need to define a DELIMITER... I like to use the pipe char "|"  (the xsd obly allows primitives)

then the code to get it into an array goes something like this.

stringp[] vals = Convert.ToString(dr.PictureURL[0]).ToArray("|");

Is that acceptable? otherwise we will think some more.
0
 
StingethAuthor Commented:
Oh so you mean store it as a normal string but delimited so that I can store and restore it into arrays?
Well thats helpful, I hadn't gone to that stage yet, but I was wondering if there is a way to define the array normally in the DataSet.
For instance, how would I define an array of ints? Your example wouldn't work for that..
0
 
gregasmCommented:
My suggestion there is to use the same approach, but there will by no strong typing for the ints. Send over the ints as a string and parse them out again.

What is the scenario where you need to send an array of ints? or strings?
0
 
StingethAuthor Commented:
I'm using the DataSet as a local database. I have a list of PictureURLs that I want to have in the dataset table, and I want it to support any number of URLs. XML supports storing multiple elements of the same name, but a C# dataset doesn't seem to support the concept. If I were reading/writing the data to XML myself of course it would be no problem, but I am using a dataset since it gives me strong typing and already has all the code there for reading/writing rows just like a database.

It has the concept of storing multiple groups of elements as far as they are a row in a table, but not multiple elements as far as the columns are concerned.

You know just now as I thought about how much the dataset was like a database, I realized that maybe the reason they don't seem to have support for multiple column data of the same element, is because you aren't really supposed to do that in a database anyways. Now that I think about it a better answer is probably to create a PictureURLs table in the dataset. If I were building a database that's what I would do anyways, I think my brain wasn't in the right mode when thinking about the dataset.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.