Groups | Blog | Home
all groups > dotnet xml > september 2004 >

dotnet xml : What's wrong with this code? Serialization


Don
9/10/2004 5:12:20 PM
Dim strSQL As String = "SELECT lastname, firstname, title, hiredate " & _

"FROM Employees "

If Len(lastname) > 0 Then

strSQL += "WHERE lastname = '" & lastname & "' "

End If

strSQL += "FOR XML AUTO"

Dim objConn As SqlConnection = New SqlConnection("Data
Source=PASWEB22D;Initial Catalog=iClas;uid=sa;password=emitsadmin;")

objConn.Open()

Dim objCmd As SqlCommand = New SqlCommand(strSQL, objConn)

Dim serializer As XmlSerializer

Dim reader As XmlTextReader

reader = objCmd.ExecuteXmlReader

Dim emp As New Employees.employee

If serializer.CanDeserialize(reader) Then <!--Code breaks here all the time
"Message: Object reference not set to an instance of an object."-->

emp = serializer.Deserialize(reader)

Else

Response.Write("Cannot Deserialize.")

End If

Emre Deniz
9/13/2004 1:37:01 PM


Because serializer is nothing. you should instanciate it. Declare it new
keyword. Good luck.



[quoted text, click to view]
AddThis Social Bookmark Button