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
Private Sub CreatePO(filename As String)
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()
myread.HasRows.ToString()
End While
Dim ds As New DataSet("Enrollment")
adapter2.Fill(ds, "Enrollment")
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)
dt.TableName = "Certificate"
dt.WriteXml("c:\pcb\my_dt.xml", False)
Dim pot As Enrollment = New Enrollment()
serializer.Serialize(writer, ds)
writer.Close()
Dim xmlDocument As XmlDocument = New XmlDocument
xmlDocument.LoadXml(ds.GetXml)
Dim doc As New XmlDocument
Dim reader As New XmlTextReader("c:\pcb\product5.xml")
reader.Read()
doc.Load(reader)
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")
End Sub