XML and strongly typed datasets

  • Thread starter Thread starter Nicholas Paldino [.NET/C# MVP]
  • Start date Start date
N

Nicholas Paldino [.NET/C# MVP]

D,

You aren't going to be able to access the representation of an image,
because only a small set of types are represented in the dataset. What is
really stored in the dataset is the serialized representation of a type.
The types that are exposed are the types that are frequently used. In the
case of the image, it is the binary representation.

You should be able to save the image to disk, or load the array into
memory and then use one of the static FromXXXX methods on the Image to get
an object representation of that image.

Hope this helps.
 
MC D said:
Because the <Images> is a Complex type, I can not access it's members
through the dataset. In other words, I can get the page title by saying
"myDataset.Page(index).PAGETITLE", but I can't get a image by saying
something like: "myDataset.Page(index).Images(index2).File"

I know you can manually build relationships in the dataset as long as there
are unique keys in both the <IMAGE> and <PAGE> elements that can be joined
on, (which is what I ended up doing) but it seems like there should be an
easier way.

Thanks a bunch for any advice!

What I do is put another dataset layer on top of the dataset generated by
VS. Then you can create all kinds of overloads and whatnot to give you the
abstraction that you want.

For example,

public class LoginsDataSet : LoginsDataSetVS {
public object Image(int PageIndex, int ImageIndex){} // or whatever.
public int FillBy1(whatever){}
public int FillBy2(whatever){}
}

where LoginsDataSetVS is the class created by VS (in my code I have a
convention of appending VS onto the class name for dataset classes generated
by VS (ie the dataset name in Properties)).

-- Alan
 
I have a situation in which I have a strongly typed dataset based on the
schema of a xml document. This works great, and OMG I love strongly typed
datasets... ;o)

However, The situation I have has a nested complex type. For example:

<PAGE>
<PAGENUMBER>1</PAGENUMBER>
<PAGETITLE>This is the title</PAGETITLE>
<IMAGES>
<IMAGE NAME="Image1" FILE="image1.jpg" />
<IMAGE NAME="Image2" FILE="image2.jpg" />
<IMAGE NAME="Image3" FILE="image3.jpg" />
</IMAGES>
</PAGE>

(or something to that effect, you get the idea)

Because the <Images> is a Complex type, I can not access it's members
through the dataset. In other words, I can get the page title by saying
"myDataset.Page(index).PAGETITLE", but I can't get a image by saying
something like: "myDataset.Page(index).Images(index2).File"

I know you can manually build relationships in the dataset as long as there
are unique keys in both the <IMAGE> and <PAGE> elements that can be joined
on, (which is what I ended up doing) but it seems like there should be an
easier way.

Thanks a bunch for any advice!

-D
 
I guess I can see that...

I guess, really, my point is that the dataset can see that there is a
complex type within a complex type, so it knows that one property of the
"PAGE" class will be a collection of "IMAGES", yet when I look at the code
insight there is no collection for "images" _UNDERNEATH_ the <PAGE> level.,
and I was wondering if there is an easier way to do this that I just wasn't
seeing, since it's the first time I've done this.

Thanks for everyones help.

-D
 
Back
Top