|
-
Mar 10th, 2010, 10:44 AM
#1
[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 /d /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:
Private Sub cmdXML_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdXML.Click
Dim emp As New EMPLOYEE_COLLECTION
Dim empDataTable As New EMPLOYEE_COLLECTION.EMPLOYEE_RECORDDataTable
Dim empDataRow As New EMPLOYEE_COLLECTION.EMPLOYEE_RECORDRow
Dim empDataReader As DataTableReader = empDataTable.CreateDataReader()
Dim x As Integer
For x = 1 To 5
empDataRow.EMPLOYEE_NO = "AISGM"
empDataRow.FIRSTNAME = "Abhijit"
empDataRow.LASTNAME = "IsGettingMad"
empDataRow.NTID = "DONTGETMAD"
empDataTable.AddEMPLOYEE_RECORDRow(empDataRow)
empDataRow.ClearErrors()
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:
Partial Public Class EMPLOYEE_RECORDRow
Inherits Global.System.Data.DataRow
Private tableEMPLOYEE_RECORD As EMPLOYEE_RECORDDataTable
<Global.System.Diagnostics.DebuggerNonUserCodeAttribute(), _
Global.System.CodeDom.Compiler.GeneratedCodeAttribute("System.Data.Design.TypedDataSetGenerator", "4.0.0.0")> _
Friend Sub New(ByVal rb As Global.System.Data.DataRowBuilder)
MyBase.New(rb)
Me.tableEMPLOYEE_RECORD = CType(Me.Table, EMPLOYEE_RECORDDataTable)
End Sub
Sub New()
' TODO: Complete member initialization
'I AM UNABLE TO ADD ANY CODE HERE.
End Sub
<Global.System.Diagnostics.DebuggerNonUserCodeAttribute(), _
Global.System.CodeDom.Compiler.GeneratedCodeAttribute("System.Data.Design.TypedDataSetGenerator", "4.0.0.0")> _
Public Property EMPLOYEE_NO() As String
Get
Return CType(Me(Me.tableEMPLOYEE_RECORD.EMPLOYEE_NOColumn), String)
End Get
Set(ByVal value As String)
Me(Me.tableEMPLOYEE_RECORD.EMPLOYEE_NOColumn) = value
End Set
End Property
<Global.System.Diagnostics.DebuggerNonUserCodeAttribute(), _
Global.System.CodeDom.Compiler.GeneratedCodeAttribute("System.Data.Design.TypedDataSetGenerator", "4.0.0.0")> _
Public Property FIRSTNAME() As String
Get
Return CType(Me(Me.tableEMPLOYEE_RECORD.FIRSTNAMEColumn), String)
End Get
Set(ByVal value As String)
Me(Me.tableEMPLOYEE_RECORD.FIRSTNAMEColumn) = value
End Set
End Property
<Global.System.Diagnostics.DebuggerNonUserCodeAttribute(), _
Global.System.CodeDom.Compiler.GeneratedCodeAttribute("System.Data.Design.TypedDataSetGenerator", "4.0.0.0")> _
Public Property LASTNAME() As String
Get
Return CType(Me(Me.tableEMPLOYEE_RECORD.LASTNAMEColumn), String)
End Get
Set(ByVal value As String)
Me(Me.tableEMPLOYEE_RECORD.LASTNAMEColumn) = value
End Set
End Property
<Global.System.Diagnostics.DebuggerNonUserCodeAttribute(), _
Global.System.CodeDom.Compiler.GeneratedCodeAttribute("System.Data.Design.TypedDataSetGenerator", "4.0.0.0")> _
Public Property NTID() As String
Get
Return CType(Me(Me.tableEMPLOYEE_RECORD.NTIDColumn), String)
End Get
Set(ByVal value As String)
Me(Me.tableEMPLOYEE_RECORD.NTIDColumn) = value
End Set
End Property
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
-
Mar 10th, 2010, 10:48 AM
#2
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
-
Mar 10th, 2010, 11:31 AM
#3
Re: XSD, DataSet and a XML file.
 Originally Posted by techgnome
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
-
Mar 10th, 2010, 11:36 AM
#4
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
-
Mar 15th, 2010, 08:32 AM
#5
Re: XSD, DataSet and a XML file.
This is the code that works:
VB.NET Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Try
Dim myEmpDS As New EMPLOYEE_COLLECTION.EMPLOYEE_RECORDDataTable
Dim myempDsRow As EMPLOYEE_COLLECTION.EMPLOYEE_RECORDRow
'If I wish to loop, this is the place to do it.
myempDsRow = myEmpDS.NewRow()
myempDsRow.EMPLOYEE_NO = "ABHIJIT"
myempDsRow.FIRSTNAME = "ABHIJIT"
myempDsRow.LASTNAME = "ABHIJIT"
myempDsRow.NTID = "ABHIJIT"
myEmpDS.AddEMPLOYEE_RECORDRow(myempDsRow)
myEmpDS.WriteXml("hello.xml")
Catch ex As Exception
MsgBox(ex.InnerException)
End Try
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
-
Mar 15th, 2010, 08:32 AM
#6
Re: XSD, DataSet and a XML file.
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|