XML Schema to Typed Dataset Primary Key Problem


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 4 of 4

Thread: XML Schema to Typed Dataset Primary Key Problem

  1. #1
    Eric Immerman Guest

    XML Schema to Typed Dataset Primary Key Problem

    I have an XML Schema (A piece of which is listed below) that I have
    converted to a Typed Dataset using .NET. In my VB app I declare a var as
    the dataset and then I add a bunch of rows. My problem is that for some
    reason when I try and get the Primary Key of any of the tables in the
    dataset I recieve and error saying that no Primary Key is defined. As you
    can see from the XML schema below a primary key is defined.

    When I try and lookup the Primary Key from a specific table using the
    following method:

    Dim pkey() As DataColumn = eData.ImageInfo.PrimaryKey

    It returns an Array with a length of zero.

    Any Ideas?

    -Eric Immerman

    ImageInfo Schema:

    <xs:element name="ImageInfo">

    <xs:complexType>

    <xs:sequence>

    <xs:element name="ImageName" type="xs:string" />

    <xs:element name="Rotate" type="xs:int" nillable="true" />

    <xs:element name="Deleted" type="xs:boolean" default="false" />

    <xs:element name="ImageNo" type="xs:int" />

    <xs:element name="ImagePath" type="xs:string" />

    </xs:sequence>

    </xs:complexType>

    <xs:key name="pkeyImageInfo" msdata:PrimaryKey="true">

    <xs:selector xpath="." />

    <xs:field xpath="mstns:ImageName" />

    </xs:key>

    </xs:element>



  2. #2
    maxcaber Guest

    Re: XML Schema to Typed Dataset Primary Key Problem


    "Eric Immerman" <eimmerman@earthlink.net> wrote:
    Eric,
    1.Are you first loading the XMLSchema for the DataSet?
    2.How are you filling the DataSet? With a DataAdapeter? If so have you
    set the MissingSchema property?
    3.Keep reminding me to dig up a solution for you, I know I have done this
    before, I am just really busy now, but this is one DataSet example that I
    want to include in my manual, beacuse I rememeber that I had a hard time
    finding the solution to this real world problem the first time that I did
    it.
    Don't drop this thread or e-mail me so I don't forget,
    Max


    >I have an XML Schema (A piece of which is listed below) that I have
    >converted to a Typed Dataset using .NET. In my VB app I declare a var as
    >the dataset and then I add a bunch of rows. My problem is that for some
    >reason when I try and get the Primary Key of any of the tables in the
    >dataset I recieve and error saying that no Primary Key is defined.


  3. #3
    Eric Immerman Guest

    Re: XML Schema to Typed Dataset Primary Key Problem

    To be perfectly honest I was cheating and using the IDE tools to do the work
    for me. I created the XML Schema using the XML Schema Designer. I then
    built the typed Dataset in the IDE. I then load the Dataset by doing the
    following:
    ______________________________________
    Private eData As New evtSchema()
    ______________________________________

    evtSchema being the xmlSchema.ID property of the Schema. I never set the
    Schema Property of the Dataset because I assumed it was automatic the way I
    was creating the Dataset Object using the Schema.ID.

    I then fill the Dataset by creating new Rows in a For ... Loop something
    like this:

    ____________________________________________________________

    Dim row As DataRow
    Dim File As String
    For Each File In oFiles
    row = eData.ImageInfo.NewRow
    row("ImagePath") = File
    eData.ImageInfo.AddImageInfoRow(row)
    Next
    ______________________________________________________________

    My next course of action is going to be not using the IDE tools and
    declaring and creating everything by hand. But I really wanted to get the
    IDE method of doing this to work so that in the future I can use
    Intellisense and other IDE features when working with larger Schemas.

    Let me know your thoughts,
    Eric Immerman


    "maxcaber" <maxcaber@yahoo.com> wrote in message
    news:3cdf4c64$1@10.1.10.29...
    >
    > "Eric Immerman" <eimmerman@earthlink.net> wrote:
    > Eric,
    > 1.Are you first loading the XMLSchema for the DataSet?
    > 2.How are you filling the DataSet? With a DataAdapeter? If so have you
    > set the MissingSchema property?
    > 3.Keep reminding me to dig up a solution for you, I know I have done this
    > before, I am just really busy now, but this is one DataSet example that I
    > want to include in my manual, beacuse I rememeber that I had a hard time
    > finding the solution to this real world problem the first time that I did
    > it.
    > Don't drop this thread or e-mail me so I don't forget,
    > Max
    >
    >
    > >I have an XML Schema (A piece of which is listed below) that I have
    > >converted to a Typed Dataset using .NET. In my VB app I declare a var as
    > >the dataset and then I add a bunch of rows. My problem is that for some
    > >reason when I try and get the Primary Key of any of the tables in the
    > >dataset I recieve and error saying that no Primary Key is defined.




  4. #4
    max caber Guest

    Re: XML Schema to Typed Dataset Primary Key Problem


    "Eric Immerman" <eimmerman@earthlink.net> wrote:
    >To be perfectly honest I was cheating and using the IDE tools to do the

    work
    >for me.

    Cheating only hurts yourself, and an IDE is the manifestation of that old
    saying. The following is what you need, pardon the C#, but its the same
    in VB.NET. The key is to call "ds.ReadXmlSchema("Pubs.xsd");"

    static void createXMLFromDataSet()
    {
    SqlDataAdapter da = new SqlDataAdapter("Selectau_id,au_fname,au_lname,contract
    from authors",cnString);
    ds = new DataSet("Pubs");
    da.FillSchema(ds,SchemaType.Source ,"Authors");
    da.Fill(ds,"author");
    ds.WriteXml("Pubs.xml");
    ds.WriteXmlSchema("Pubs.xsd");
    }

    static void createDataSetFromXML()
    {
    ds = new DataSet("Pubs");
    ds.ReadXmlSchema("Pubs.xsd");
    ds.ReadXml("Pubs.xml");
    foreach(System.Data.Constraint cnst in ds.Tables[0].Constraints)
    {
    Console.WriteLine("Constraint Name:= " + cnst.ConstraintName);
    Console.WriteLine("Constraint Type:= " + cnst.GetType().ToString());
    }
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center