Click here to Skip to main content
15,887,812 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi
I have trouble getting this following vb.net code to process the serialization of a ms sql table to xml document. The document is an XML complex type with nested loops. I am lost on how to get the dataset to the serializer. There is a class created by XSD.exe I have used called Enrollment. I have not included this class code -2400 lines. If you need this please let me know.

Its the data that I cannot understand how to move to the serializer. Any tips or help will be very much appreciated, I am a week behind to get this working.

Some code below is to make other xml document output but they are not processed using the class from XSD.exe. I am not seeing something I have to do to get the MS sql table to this class'ed xml output.

Your help is appreciated.

Thanks
Trevor

The code
VB
Private Sub CreatePO(filename As String)
    ' Creates an instance of the XmlSerializer class;
    ' specifies the type of object to serialize.
    Dim adapter2 As SqlDataAdapter
    Dim dt As DataTable
    Dim dr As DataRow
    


    Dim PBC_db_connect As String = ConfigurationManager.ConnectionStrings("PBC_db_connect2").ConnectionString
    
    Dim select_member_table_values As String = "SELECT  rowid, batch_id, member_no, student_id, group_no, realcode_fall, realcode_winter, realcode_summer, cov_code_fall, cov_code_winter, cov_code_summer, last_name, first_name, gender, DOB, health_start, dental_start, health_end, dental_end, cancel_reason, cov_declined_health, cov_declined_dental, default_email,default_phone, termination_date FROM PBC_member WHERE(do_not_resend = 0)"
    
    Dim myread As SqlDataReader
    

    Dim fs2 As FileStream = New FileStream("c:\pcb\mytest2.xml", FileMode.OpenOrCreate)
    Using myConnection2 As New SqlConnection(PBC_db_connect)
    	myConnection2.Open()
	adapter2 = New SqlDataAdapter(select_member_table_values, myConnection2)

	Dim myCommand1 As New SqlCommand(select_member_table_values, myConnection2)
	myCommand1.CommandType = CommandType.Text

	myread = myCommand1.ExecuteReader()

	While myread.Read()
		'	Response.Write("<br /> what is that <br />")

        	myread.HasRows.ToString()

	End While

	Dim ds As New DataSet("Enrollment")
	adapter2.Fill(ds, "Enrollment")



	'adapter2.Fill(dt)

	'	Response.Flush()
	ds.WriteXml("c:\pcb\Product5.xml", XmlWriteMode.WriteSchema)

	Dim xmlSW2 As System.IO.StreamWriter = New System.IO.StreamWriter("c:\pcb\Product4.xml")
	ds.WriteXml(xmlSW2, XmlWriteMode.DiffGram)
	xmlSW2.Flush()
	xmlSW2.Close()

	Dim serializer As New XmlSerializer(GetType(Enrollment))
	Dim writer As New StreamWriter("c:\pcb\product3.xml")
	Dim po As New Enrollment()


	dt = ds.Tables(0)
	'	For Each dr In dt.Rows
	dt.TableName = "Certificate"

	'Next

	'dt.ReadXmlSchema("c:\pcb\pol_1.xsd")

	dt.WriteXml("c:\pcb\my_dt.xml", False)

	Dim pot As Enrollment = New Enrollment()

	' Inserts the item into the array.
	'Dim items(0) As Enrollment
	'i() 'tems(0) = i1
	' Serializes the purchase order, and close the TextWriter.
	serializer.Serialize(writer, ds)
	writer.Close()

	Dim xmlDocument As XmlDocument = New XmlDocument
	xmlDocument.LoadXml(ds.GetXml)

	Dim doc As New XmlDocument
	'Load the the document with the last book node.
	Dim reader As New XmlTextReader("c:\pcb\product5.xml")
	reader.Read()
	doc.Load(reader)
	'doc.open(Console.Out)


	'Response.Clear()
	'Response.Write.ContentType = "text/xml"
	'Response.ContentEncoding = Encoding.UTF8
	'Response.Write(xmlDocument.InnerXml)
	'Response.End()


    End Using

End Sub



Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

    Dim t As New _1ser_test1()
    t.CreatePO("c:\pcb\pot3.xml")
    't.ReadPO("c:\pcb\pot4.xml")
    
End Sub
Posted
Updated 9-Sep-14 16:44pm
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900