|
-
Jan 27th, 2004, 09:49 AM
#1
Thread Starter
Fanatic Member
A little help
I am newbie in VB.NET. I just trying to create a xml file and then read back.
What is wrong in this code?
The File is not created
Imports System.Xml.Serialization.XmlSerializer
Imports System.IO
Imports System.Console
Module Module1
Sub Main()
End Sub
Sub testingXml()
Dim Ser As New Xml.Serialization.XmlSerializer(GetType(Customer))
Dim Cust As New Customer(1, "Luis Moises", "EL CARIBE", "Santo Domingo")
Dim Fs As New FileStream("c:\lmr\customer.xml", FileMode.Create)
Ser.Serialize(Fs, Cust)
Fs.Close()
Dim Fs2 As New FileStream("c:\lmr\customer.xml", FileMode.Open)
Dim Cust2 As New Customer
Cust2 = CType(Ser.Deserialize(Fs2), Customer)
Fs2.Close()
End Sub
Public Class Customer
Dim ID As Integer
Dim Nombre As String
Dim Direccion As String
Dim Ciudad As String
Sub New()
End Sub
Sub New(ByVal id As Integer, ByVal nombre As String, ByVal direccion As String, ByVal ciudad As String)
Me.ID = id
Me.Nombre = nombre
Me.Direccion = direccion
Me.Ciudad = ciudad
End Sub
End Class
End Module
-
Jan 27th, 2004, 10:02 AM
#2
you need to declare the Class " Dim Cust As New Customer " before declaring the XmlSerializer at a guess , because your trying to get an empty type with the part that says ... (GetType(Customer))
, eg:
VB Code:
Dim Cust As New Customer(1, "Luis Moises", "EL CARIBE", "Santo Domingo")
Dim Ser As New Xml.Serialization.XmlSerializer(GetType(Cust))
~
if a post is resolved, please mark it as [Resolved]
protected string get_Signature(){return Censored;}
[vbcode][php] please use code tags when posting any code [/php][/vbcode]
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
|