Results 1 to 6 of 6

Thread: [RESOLVED] XSD, DataSet and a XML file.

  1. #1

    Thread Starter
    PowerPoster abhijit's Avatar
    Join Date
    Jun 1999
    Location
    Chit Chat Forum.
    Posts
    3,228

    Resolved [RESOLVED] XSD, DataSet and a XML file.

    My requirement is to create a XML file based on an XSD.
    The source data for this file will be coming from a database. For the purposes of this test, I am trying to manually assign the values.

    I followed these steps:

    1) Used the XSD.exe to create a VB Class.
    PHP Code:
    xsd //l:VB emprec.xsd /n:XSDSchema.EmpCollection 
    2) Added the VB Class in my project.
    3) If I try to compile my code, I get an error.

    Here's the code I wrote:
    VB.NET Code:
    1. Private Sub cmdXML_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdXML.Click
    2.         Dim emp As New EMPLOYEE_COLLECTION
    3.         Dim empDataTable As New EMPLOYEE_COLLECTION.EMPLOYEE_RECORDDataTable
    4.         Dim empDataRow As New EMPLOYEE_COLLECTION.EMPLOYEE_RECORDRow
    5.  
    6.         Dim empDataReader As DataTableReader = empDataTable.CreateDataReader()
    7.  
    8.         Dim x As Integer
    9.  
    10.         For x = 1 To 5
    11.             empDataRow.EMPLOYEE_NO = "AISGM"
    12.             empDataRow.FIRSTNAME = "Abhijit"
    13.             empDataRow.LASTNAME = "IsGettingMad"
    14.             empDataRow.NTID = "DONTGETMAD"
    15.             empDataTable.AddEMPLOYEE_RECORDRow(empDataRow)
    16.             empDataRow.ClearErrors()
    17.         Next x

    The error I get is
    PHP Code:
    Error    1    First statement of this 'Sub New' must be a call to 'MyBase.New' or 'MyClass.New' because base class 'System.Data.DataRow' of 'writeXMLbasedonXSD.XSDSchema.EmpCollection.EMPLOYEE_COLLECTION.EMPLOYEE_RECORDRow' does not have an accessible 'Sub New' that can be called with no arguments.    D:\Visual Studio 2010\Projects\writeXMLbasedonXSD\writeXMLbasedonXSD\emprec.vb    598    17    writeXMLbasedonXSD 
    This is the code from the class that was generated using XSD utility.
    VB.NET Code:
    1. Partial Public Class EMPLOYEE_RECORDRow
    2.             Inherits Global.System.Data.DataRow
    3.  
    4.             Private tableEMPLOYEE_RECORD As EMPLOYEE_RECORDDataTable
    5.  
    6.             <Global.System.Diagnostics.DebuggerNonUserCodeAttribute(), _
    7.              Global.System.CodeDom.Compiler.GeneratedCodeAttribute("System.Data.Design.TypedDataSetGenerator", "4.0.0.0")> _
    8.             Friend Sub New(ByVal rb As Global.System.Data.DataRowBuilder)
    9.                 MyBase.New(rb)
    10.                 Me.tableEMPLOYEE_RECORD = CType(Me.Table, EMPLOYEE_RECORDDataTable)
    11.             End Sub
    12.  
    13.             Sub New()
    14.                 ' TODO: Complete member initialization
    15.  
    16.                 'I AM UNABLE TO ADD ANY CODE HERE.
    17.             End Sub
    18.  
    19.             <Global.System.Diagnostics.DebuggerNonUserCodeAttribute(), _
    20.              Global.System.CodeDom.Compiler.GeneratedCodeAttribute("System.Data.Design.TypedDataSetGenerator", "4.0.0.0")> _
    21.             Public Property EMPLOYEE_NO() As String
    22.                 Get
    23.                     Return CType(Me(Me.tableEMPLOYEE_RECORD.EMPLOYEE_NOColumn), String)
    24.                 End Get
    25.                 Set(ByVal value As String)
    26.                     Me(Me.tableEMPLOYEE_RECORD.EMPLOYEE_NOColumn) = value
    27.                 End Set
    28.             End Property
    29.  
    30.             <Global.System.Diagnostics.DebuggerNonUserCodeAttribute(), _
    31.              Global.System.CodeDom.Compiler.GeneratedCodeAttribute("System.Data.Design.TypedDataSetGenerator", "4.0.0.0")> _
    32.             Public Property FIRSTNAME() As String
    33.                 Get
    34.                     Return CType(Me(Me.tableEMPLOYEE_RECORD.FIRSTNAMEColumn), String)
    35.                 End Get
    36.                 Set(ByVal value As String)
    37.                     Me(Me.tableEMPLOYEE_RECORD.FIRSTNAMEColumn) = value
    38.                 End Set
    39.             End Property
    40.  
    41.             <Global.System.Diagnostics.DebuggerNonUserCodeAttribute(), _
    42.              Global.System.CodeDom.Compiler.GeneratedCodeAttribute("System.Data.Design.TypedDataSetGenerator", "4.0.0.0")> _
    43.             Public Property LASTNAME() As String
    44.                 Get
    45.                     Return CType(Me(Me.tableEMPLOYEE_RECORD.LASTNAMEColumn), String)
    46.                 End Get
    47.                 Set(ByVal value As String)
    48.                     Me(Me.tableEMPLOYEE_RECORD.LASTNAMEColumn) = value
    49.                 End Set
    50.             End Property
    51.  
    52.             <Global.System.Diagnostics.DebuggerNonUserCodeAttribute(), _
    53.              Global.System.CodeDom.Compiler.GeneratedCodeAttribute("System.Data.Design.TypedDataSetGenerator", "4.0.0.0")> _
    54.             Public Property NTID() As String
    55.                 Get
    56.                     Return CType(Me(Me.tableEMPLOYEE_RECORD.NTIDColumn), String)
    57.                 End Get
    58.                 Set(ByVal value As String)
    59.                     Me(Me.tableEMPLOYEE_RECORD.NTIDColumn) = value
    60.                 End Set
    61.             End Property
    62.         End Class

    How do I resolve this? I am unable to add any code in the 'TODO section for this generated class. What am I missing?
    Everything that has a computer in will fail. Everything in your life, from a watch to a car to, you know, a radio, to an iPhone, it will fail if it has a computer in it. They should kill the people who made those things.- 'Woz'
    save a blobFileStreamDataTable To Text Filemy blog

  2. #2
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: XSD, DataSet and a XML file.

    I don't know why you "can't" but all you need in your New() constructor is "MyBase.New" ... because the class is inherited, you have to make sure you call the appropriate constructor of the inherited class.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3

    Thread Starter
    PowerPoster abhijit's Avatar
    Join Date
    Jun 1999
    Location
    Chit Chat Forum.
    Posts
    3,228

    Re: XSD, DataSet and a XML file.

    Quote Originally Posted by techgnome View Post
    I don't know why you "can't" but all you need in your New() constructor is "MyBase.New" ... because the class is inherited, you have to make sure you call the appropriate constructor of the inherited class.

    -tg
    I tried to use MyBase.New() in the class, but it threw this error.
    PHP Code:
    Error    1    Argument not specified for parameter 'builder' of 'Protected Friend Sub New(builder As System.Data.DataRowBuilder)'.    C:\\Projects\\writeXMLbasedonXSD\\writeXMLbasedonXSD\\emprec.vb    596    17    writeXMLbasedonXSD 
    So I tried to correct it using this code
    MyBase.New(builder as Global.System.Data.DataRowBuilder)
    That throws up an error as well.

    It seems I cannot use an object that has not been created yet.
    Everything that has a computer in will fail. Everything in your life, from a watch to a car to, you know, a radio, to an iPhone, it will fail if it has a computer in it. They should kill the people who made those things.- 'Woz'
    save a blobFileStreamDataTable To Text Filemy blog

  4. #4
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: XSD, DataSet and a XML file.

    wait... does the class you are inheriting from even have a parameterless constructor?

    Also, of course you can't use an object you haven't created... you can't drive a car that hasn't been built, can you? What you need to do is CREATE the instance of the object and pass it in.

    But if the class you are inheriting from doesn't even have a parameterless constructor, then you can actually remove yours, and it should be OK.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  5. #5

    Thread Starter
    PowerPoster abhijit's Avatar
    Join Date
    Jun 1999
    Location
    Chit Chat Forum.
    Posts
    3,228

    Re: XSD, DataSet and a XML file.

    This is the code that works:

    VB.NET Code:
    1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    2.  
    3.         Try
    4.             Dim myEmpDS As New EMPLOYEE_COLLECTION.EMPLOYEE_RECORDDataTable
    5.             Dim myempDsRow As EMPLOYEE_COLLECTION.EMPLOYEE_RECORDRow
    6. 'If I wish to loop, this is the place to do it.
    7.             myempDsRow = myEmpDS.NewRow()
    8.             myempDsRow.EMPLOYEE_NO = "ABHIJIT"
    9.             myempDsRow.FIRSTNAME = "ABHIJIT"
    10.             myempDsRow.LASTNAME = "ABHIJIT"
    11.             myempDsRow.NTID = "ABHIJIT"
    12.             myEmpDS.AddEMPLOYEE_RECORDRow(myempDsRow)
    13.             myEmpDS.WriteXml("hello.xml")
    14.         Catch ex As Exception
    15.             MsgBox(ex.InnerException)
    16.         End Try
    17.     End Sub
    Everything that has a computer in will fail. Everything in your life, from a watch to a car to, you know, a radio, to an iPhone, it will fail if it has a computer in it. They should kill the people who made those things.- 'Woz'
    save a blobFileStreamDataTable To Text Filemy blog

  6. #6

    Thread Starter
    PowerPoster abhijit's Avatar
    Join Date
    Jun 1999
    Location
    Chit Chat Forum.
    Posts
    3,228

    Re: XSD, DataSet and a XML file.

    How do I serialize this?
    Everything that has a computer in will fail. Everything in your life, from a watch to a car to, you know, a radio, to an iPhone, it will fail if it has a computer in it. They should kill the people who made those things.- 'Woz'
    save a blobFileStreamDataTable To Text Filemy blog

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width