[Last Call] Learn how to a build a cloud-first strategyRegister Now


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

Posted on 2005-04-05
Medium Priority
Last Modified: 2013-11-19

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";

Question by:Stingeth
  • 3
  • 2

Expert Comment

ID: 13713529
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.

Author Comment

ID: 13716826
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..

Expert Comment

ID: 13721847
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?

Author Comment

ID: 13722533
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.

Accepted Solution

gregasm earned 2000 total points
ID: 13723977
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...


Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…
Suggested Courses

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question