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

Posted on 2005-04-05
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
    LVL 8

    Expert Comment

    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

    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..
    LVL 8

    Expert Comment

    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

    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.
    LVL 8

    Accepted Solution

    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...


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Enabling OSINT in Activity Based Intelligence

    Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

    This article covers the basics of the Sass, which is a CSS extension language. You will learn about variables, mixins, and nesting.
    It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that undeā€¦
    The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
    The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

    759 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

    Need Help in Real-Time?

    Connect with top rated Experts

    8 Experts available now in Live!

    Get 1:1 Help Now