473,396 Members | 2,036 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

What's wrong with this code? Serialization

Don
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
Nov 12 '05 #1
1 1251


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

Don wrote:
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

Nov 12 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
by: Alfonso Morra | last post by:
Hi, I am at the end of my tether now - after spending several days trying to figure how to do this. I have finally written a simple "proof of concept" program to test serializing a structure...
9
by: Jiho Han | last post by:
Suppose I have an xml fragment like: <mother> <child name="Bob" sex="M"/> <child name="Jane" sex="F"/> ... </mother> If I wanted to replace the <mother> element to <father> element, what is...
1
by: Andrea | last post by:
I was trying to deserialize my xml file (I enclose it below ) into a class. So I generated an xsd file given my xml using the MS xsd tool; then I generated the corresponsing C# class (using the MS...
2
by: joewhitehair | last post by:
Using the XSD.exe tool, I created a number of classes from my XSD file. When I generate the WSDL for my web service, the schema does not have the proper Occurance constraints for the attributes. In...
11
by: Alfonso Morra | last post by:
Hi, I am at the end of my tether now - after spending several days trying to figure how to do this. I have finally written a simple "proof of concept" program to test serializing a structure...
7
by: MrNobody | last post by:
I was a Java developer so I'm used to using property files as a means to keep configuration settings for my apps. I'm wondering what options are there with ..NET? Some settings I want to include...
3
by: Alex Nitulescu | last post by:
_______________________________________________________________________________________ System.IO.FileNotFoundException: File or assembly name biypfduw.dll, or one of its dependencies, was not...
6
by: DBC User | last post by:
Could someone help me understand 'Serializable'? What is this 'Serializable' why do we need it and how do we use it? Any link or simple example would be great.
0
by: groovyghoul | last post by:
Hi I have the following XML file: =========================================================== <?xml version="1.0" encoding="UTF-16"?> <Policy xmlns="http://tempuri.org/richard.xsd"> <TransType...
5
by: Smokey Grindel | last post by:
Anyone able to figure whats wrong here? It is saying it cant convert from itself to itself? I am confused on this error that the designer is throwing... One or more errors encountered while...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.