SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Script task using VB.NET to serialize data to XML file


Script task using VB.NET to serialize data to XML file

Author
Message
sqlgreenhand
sqlgreenhand
Ten Centuries
Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)

Group: General Forum Members
Points: 1351 Visits: 198
I am learning SSIS using VB.NET to serialize data to XML file with a simple class created. I am using a list
(System.Collections.Generic) to collect data before passing to XML. If I use an array it works. Anyone has this experience before or I have missed something. Please instruct me. Thanks.Angry
But somehow it always throws this error
"Error: 0x1 at Script Task: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.InvalidOperationException: There was an error generating the XML document. ---> System.TypeInitializationException: The type initializer for 'Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriterList1' threw an exception. ---> System.NullReferenceException: Object reference not set to an instance of an object."

<code>
Imports System
Imports System.Data
Imports System.Math
Imports Microsoft.SqlServer.Dts.Runtime
Imports System.Xml
Imports System.IO
Imports System.Xml.Serialization
Imports System.Collections.Generic

<System.AddIn.AddIn("ScriptMain", Version:="1.0", Publisher:="", Description:="")> _
<System.CLSCompliantAttribute(False)> _
Partial Public Class ScriptMain
Inherits Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase

Enum ScriptResults
Success = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Success
Failure = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Failure
End Enum



Public Sub Main()
'
' Add your code here
'
'Set up product object.
Dim p As New clsProduct()

p.Name = "Johnsmith"
p.Description = "New VB student"
p.Qty = "555"
Dim alist As New List(Of clsProduct)
alist.Add(p)

'Serialize object to a text file.
Dim objStreamWriter As StreamWriter = New StreamWriter("C:\\Projects\\Product.xml")


'Dim x As New XmlSerializer(p.GetType)
Dim x As XmlSerializer = New XmlSerializer(GetType(List(Of clsProduct)))
x.Serialize(objStreamWriter, alist)
objStreamWriter.Close()

Dts.TaskResult = ScriptResults.Success
End Sub
<Serializable()> Public Class clsProduct

Private mstrName As String
Private mstrDescription As String
Private mintQty As String
Public Sub New()
Name = ""
Description = "'"
Qty = ""
End Sub
Public Property Name() As String
Get
Name = mstrName
End Get
Set(ByVal Value As String)
mstrName = Value
End Set
End Property

Public Property Description() As String
Get
Description = mstrDescription
End Get
Set(ByVal Value As String)
mstrDescription = Value
End Set
End Property

Public Property Qty() As String
Get
Qty = mintQty
End Get
Set(ByVal Value As String)
mintQty = Value
End Set
End Property

End Class
End Class

</code>
sqlgreenhand
sqlgreenhand
Ten Centuries
Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)

Group: General Forum Members
Points: 1351 Visits: 198
Any VB.NET expert who could share this ?!
Thanks.Sad
CozyRoc
CozyRoc
One Orange Chip
One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)

Group: General Forum Members
Points: 26774 Visits: 2235
sqlgreenhand (12/8/2011)
Any VB.NET expert who could share this ?!
Thanks.Sad


This is not the best place for this question. Try posting here.

---
SSIS Tasks Components Scripts Services | http://www.cozyroc.com/


sqlgreenhand
sqlgreenhand
Ten Centuries
Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)

Group: General Forum Members
Points: 1351 Visits: 198
Thanks.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum









































































































































































SQLServerCentral


Search