Click here to Skip to main content
14,364,399 members
Rate this:
Please Sign up or sign in to vote.
I need a help
i would like create an web service asmx who return arraylist from sql server !
i have an error System.NullReferenceException: la reference de l'objet n'est pas definie une instance de l'objet
<webmethod()> _
Public Function data() As ArrayList()
Dim con As New SqlConnection
con.ConnectionString = "Data Source=.;Initial Catalog=personnel;Integrated Security=True"
Dim Sql As String = "select Nom from Employes "
Sql = String.Format(Sql)
Dim Command As New SqlCommand(Sql, con)
Dim dr As SqlDataReader
dr = Command.ExecuteReader()
'Dim result = ""
While dr.Read()
Return result.ToArray
End While
Return result.ToArray
Dim sas As String
Dim x As New web_servive_array.Web
sas =
Return result.ToArray
End Function

please help
Updated 24-Mar-15 18:56pm
Andy Lanng 24-Mar-15 9:06am
This is not C# - Please remove the tag.
Joan Magnet 24-Mar-15 12:52pm
Usually you get a NullReferenceException when some object has not been initialized.

Put your code inside a normal console or winform app and debug it.

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

Hi, First of all it's VB.Net code so remove C# tag from your question :).
The exception that is thrown when there is an attempt to dereference a null object reference.
For more information see this :[^]
Try to debug your code and it will be better if you specify on which line you are getting this error.

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

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100