Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
1.00/5 (1 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
-------------------------------------------------
VB
<webmethod()> _
Public Function data() As ArrayList()
Dim con As New SqlConnection
con.ConnectionString = "Data Source=.;Initial Catalog=personnel;Integrated Security=True"
con.Open()
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()
result.Add(dr(0).ToString)
Return result.ToArray
End While
Return result.ToArray
Dim sas As String
Dim x As New web_servive_array.Web
sas = x.data(Sql).ToString
con.Close()
Return result.ToArray
End Function

----------------------------------------------------
please help
Posted
Updated 24-Mar-15 17:56pm
v2
Comments
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

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 : https://msdn.microsoft.com/en-us/library/system.nullreferenceexception%28v=vs.110%29.aspx[^]
Try to debug your code and it will be better if you specify on which line you are getting this error.
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900