Array of public Structure Help me PLEASE!

kiwi

Member
Joined
Jul 12, 2006
Messages
14
Programming Experience
Beginner
Hy! I'm sorry if i can't explain my problem very well, i'm italian but i need help for a problem with vb.net program... so...

I made a web service that extract some value from a db and this result must be insered in this public structure:

VB.NET:
Public Structure SERVS1Result
Public NumeroComm As Integer
Public Comm As SComm
 
Public Structure SComm
Public Nome As String
Public Indirizzo As String
Public Cap As String
Public Comune As String
Public SiglaProvincia As String
Public Email As String
Public telefono As String
End Structure
End Structure
and then I wrote:

Return SERVS1Result (the name of my public structure)

what is the problem?
the problem is that I have many result from my db and for this I need to create a Array of my Public Structure
I try to create it but i receive some messagge error!!

I post my code and i hope that you can help me, I try to ask help in many forum but nobody say me nothing PLEASE!!!

VB.NET:
<Start of function>
Public Com() As Object '<----------------------------------------///
 
[.....code....]
 
If Not risolvi = "" Then
objConn.Open()
 
 
Dim pc As String
Dim i As Integer = 0
Dim x As Integer = 0
Dim c As Integer
Dim objCmd2 As New OleDbCommand("Stringa di connessione", objConn)
Dim objReader2 As OleDbDataReader
objReader2 = objCmd2.ExecuteReader
 
While objReader2.Read
pc = (objReader2.GetString(9))
If pc = "Y" Then
i = i + 1
 
Com(i) = New SERVS1Result '<-----------------------------------///
 
Com(i).Comm.Nome = objReader2.GetString(2) 'Sede
Com(i).Comm.Indirizzo = objReader2.GetString(4) 'indirizzo
Com(i).Comm.telefono = objReader2.GetString(5) 'telefono
Com(i).Comm.Email = objReader2.GetString(8) 'email
Com(i).Comm.Cap = CapCom
Com(i).Comm.Comune = Comune
Com(i).Comm.SiglaProvincia = Provincia
 
 
End If
 
End While
 
objConn.Close()
objConn.Dispose()
 
Com(i).NumeroComm = i '<------------------------------------------///
 
 
For c = 0 To Com.Length '<-------------------------------///
Return Com(c) '<-----------------------------///
Next
 
 
End If
 
 
End Function
 
<End Function>
 
<Start Public Structure>
Public Structure SERVS1Result
Public NumeroComm As Integer
Public Comm As SComm
 
Public Structure SComm
Public Nome As String
Public Indirizzo As String
Public Cap As String
Public Comune As String
Public SiglaProvincia As String
Public Email As String
Public telefono As String
End Structure
End Structure

thank you
 
Last edited by a moderator:
Please use code boxes when posting, either with the code-tags as decribed in forum FAQ or using the Advanced editor click the '#' code button, thank you, and welcome to the forums!

A function can only return one value, once you call Return that function is finished. You haven't posted the signature of that function, but probably have set it to return type SERVS1Result. If you want it to return an array of this type you must instruct it to do so with the '()' array qualification. So your function must return value of type SERVS1Result(). Also your 'Public Com() As Object' must be change to 'Dim Com() As SERVS1Result'. When you are ready to return from function you do 'Return Com'.

Below is example of correct WebMethod:
VB.NET:
<WebMethod()> _
Public Function getTheStructureArray() As structest()
  Dim TSA(1) As structest
  TSA(0) = New structest
  TSA(0).id = 0
  TSA(1) = New structest
  TSA(1).id = 1
  Return TSA
End Function
 
Public Structure structest
  Dim id As Integer
  Dim name As Integer
End Structure
Below is example of consuming the webservice example above (the service reference is added and its namespace here is 'localhost' and class 'Service'):
VB.NET:
Dim webserv As New localhost.Service
Dim tsa() As localhost.structest = webserv.getTheStructureArray
For i As Short = 0 To tsa.Length - 1
  MsgBox(tsa(i).id)
Next
 
Thank you for answer me, and thank to comprise my english, i'm sorry that i have post bad my code i hope this is the right way

I try this code.....
but i receive a message error, I try to translate the message:
System.NullReferenceException: reference to a object not import on a istance of a object in SERVS1ClassAccess.SERVS1(String ist)
VB.NET:
Start of function>
[SIZE=2][COLOR=#0000ff]
Public[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Function[/COLOR][/SIZE][SIZE=2] SERVS1([/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] ist [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]String[/COLOR][/SIZE][SIZE=2]) [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] SERVS1Result
[/SIZE]
.....code....
 
If Not risolvi = "" Then
objConn.Open()
 
Dim Com() As SERVS1Result '<---------------------------///
Dim pc As String
Dim i As Integer = 0
Dim x As Integer = 0
Dim c As Integer
Dim objCmd2 As New OleDbCommand("Stringa di connessione", objConn)
Dim objReader2 As OleDbDataReader
objReader2 = objCmd2.ExecuteReader
 
While objReader2.Read
pc = (objReader2.GetString(9))
If pc = "Y" Then
i = i + 1
 
Com(i) = New SERVS1Result'<-----------------------------------///
 
Com(i).Comm.Nome = objReader2.GetString(2) 'Sede
Com(i).Comm.Indirizzo = objReader2.GetString(4) 'indirizzo
Com(i).Comm.telefono = objReader2.GetString(5) 'telefono
Com(i).Comm.Email = objReader2.GetString(8) 'email
Com(i).Comm.Cap = CapCom
Com(i).Comm.Comune = Comune
Com(i).Comm.SiglaProvincia = Provincia
 
 
End If
 
End While
 
objConn.Close()
objConn.Dispose()
 
Com(i).NumeroComm = i '<------------------------------------------///
 
 
For c = 0 To Com.Length '<-------------------------------///
Return Com(c) '<-----------------------------///
Next
 
 
End If
 
 
End Function
 
<End Function>
 
<Start Public Structure> 'this is the structure that i must use
Public Structure SERVS1Result
Public NumeroComm As Integer
Public Comm As SComm
 
Public Structure SComm
Public Nome As String
Public Indirizzo As String
Public Cap As String
Public Comune As String
Public SiglaProvincia As String
Public Email As String
Public telefono As String
End Structure
End Structure
 
You must change the return value in function signature to:
VB.NET:
Public Function SERVS1(ByVal ist As String) As SERVS1Result[B][COLOR=darkgreen]()[/COLOR][/B]
And you must return the Com array:

VB.NET:
[COLOR=black]Return [/COLOR][COLOR=darkgreen][B]Com[/B][/COLOR]
You must also redimension the array: (EDIT, I forgot to Preserve, of course you have to preserve the earlier items)
VB.NET:
While objReader2.Read
pc = (objReader2.GetString(9))
If pc = "Y" Then
[COLOR=darkgreen][B]ReDim Preserve Com(i)[/B][/COLOR]
Com(i).Comm.Nome = objReader2.GetString(2) 'Sede
...
... 
[COLOR=darkgreen][B]i = i + 1[/B][/COLOR] 
End If
 
End While
Your "Com(i).NumeroComm = i" after the EndWhile I don't understand.
 
Last edited:
thanks, thanks I try your solution immediately and i post the answer
com(i).NumeroComm = i

is the count of the result that the db extract....
 
wow you are a genius thanks thanks thanks thanks I'm sooooo Happy

the last question:
if i want repeat only one parte of the structure?

Public Structure SERVS1Result 'no this part
Public NumeroComm As Integer 'no this part
Public Comm As SComm
---------------------------only this part------------------
Public Structure SComm
Public Nome As String
Public Indirizzo As String
Public Cap As String
Public Comune As String
Public SiglaProvincia As String
Public Email As String
Public telefono As String
End Structure
-----------------------only this part---------------------

End Structure
 
Sorry i don't want to disturb you again you are so polite and so clever, but my result must be so:

VB.NET:
[COLOR=#0000ff][COLOR=#000000]<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd=
"http://www.w3.org/2001/XMLSchema" xmlns:soap=
"http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <SERVS1Response xmlns="http://www.contoso.com/Response">
      <SERVS1Result> '---------> one time
         <NumeroComm>[/COLOR][COLOR=#00008b][B]int[/B][/COLOR][COLOR=#000000]</NumeroComm> '---------------> one time
          <Comm> ' the name of the istance of SComm in the structure[/COLOR][/COLOR]
[COLOR=#0000ff][COLOR=#000000]           <SComm> '------------> only this part must be repeat for each result from the db
            <Nome>[/COLOR][COLOR=#00008b][B]string[/B][/COLOR][COLOR=#000000]</Nome>
            <Indirizzo>[/COLOR][COLOR=#00008b][B]string[/B][/COLOR][COLOR=#000000]</Indirizzo>
            <Cap>[/COLOR][COLOR=#00008b][B]string[/B][/COLOR][COLOR=#000000]</Cap>
            <Comune>[/COLOR][COLOR=#00008b][B]string[/B][/COLOR][COLOR=#000000]</Comune>
            <SiglaProvincia>[/COLOR][COLOR=#00008b][B]string[/B][/COLOR][COLOR=#000000]</SiglaProvincia>
            <Email>[/COLOR][COLOR=#00008b][B]string[/B][/COLOR][COLOR=#000000]</Email>
            <telefono>[/COLOR][COLOR=#00008b][B]string[/B][/COLOR][COLOR=#000000]</telefono>
          [COLOR=#000000]</SComm> '------------> only this part must be repeat for each result from the db[/COLOR][/COLOR][/COLOR]
[COLOR=#0000ff][COLOR=#000000]            [COLOR=#000000]<SComm>[/COLOR]
            <Nome>[/COLOR][COLOR=#00008b][B]string[/B][/COLOR][COLOR=#000000]</Nome>
            <Indirizzo>[/COLOR][COLOR=#00008b][B]string[/B][/COLOR][COLOR=#000000]</Indirizzo>
            <Cap>[/COLOR][COLOR=#00008b][B]string[/B][/COLOR][COLOR=#000000]</Cap>
            <Comune>[/COLOR][COLOR=#00008b][B]string[/B][/COLOR][COLOR=#000000]</Comune>
            <SiglaProvincia>[/COLOR][COLOR=#00008b][B]string[/B][/COLOR][COLOR=#000000]</SiglaProvincia>
            <Email>[/COLOR][COLOR=#00008b][B]string[/B][/COLOR][COLOR=#000000]</Email>
            <telefono>[/COLOR][COLOR=#00008b][B]string[/B][/COLOR][COLOR=#000000]</telefono>
          </[COLOR=#000000]SComm>[/COLOR][/COLOR][/COLOR]
[COLOR=#0000ff][COLOR=#000000]       </Comm>
        </SERVS1Result>
    </SERVS1Response>
  </soap:Body>
</soap:Envelope>[/COLOR][/COLOR]
 
You could do one of two things.
1. Repeat the SComm members (not very elegant - Nome1, Nome2, Indirizzo1, Indirizzo2 ...)
2. change SERVS1Result.Comm to a two elements array (Dim Comm() As SComm)

Some helpful advice: If you choose option 2 the you must also remember to Redim the Comm member for each new SERVS1Result because arrays declared as structure members cannot be declared with an initial size. Alternatively change the SERVS1Result structure into a class, which allow initial size array members (Dim Comm(1) As SComm). Either way you will then fill Com(i).Comm(0).member and Com(i).Comm(1).member. For the class alternative instance construction is also required (Com(i) = New SERVS1Result)
 
I really can't explain how many you make me happy with your help, my english don't allow me to say it... so tomorrow I will try your second solution and give you the result.....or other problem, i don't know!
Now I'm a girl dead for the sleep (can I say so in english?)
thanks again and again and again................

Goodnight
 
I try this way, but somethings go wrong......
VB.NET:
[COLOR=#0000ff]Public[SIZE=2]Function[/SIZE][/COLOR][SIZE=2] SERVS1([/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] ist [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]String[/COLOR][/SIZE][SIZE=2]) [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] SERVS1Result
[/SIZE]
.....code....
 
[SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Not[/COLOR][/SIZE][SIZE=2] risolvi = [/SIZE][SIZE=2][COLOR=#800000]""[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Then
[/COLOR][/SIZE][SIZE=2]objConn.Open()
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] Com() [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] SERVS1Result [/SIZE][SIZE=2][COLOR=#008000]'Giusto
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] Comm() [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] SERVS1Result.SComm '<---------//
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] pc [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]String
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] i [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Integer[/COLOR][/SIZE][SIZE=2] = 0
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] x [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Integer[/COLOR][/SIZE][SIZE=2] = 0
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] c [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Integer
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] objCmd2 [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] OleDbCommand([/SIZE][SIZE=2][COLOR=#800000]"Connection string[/COLOR][/SIZE][SIZE=2][COLOR=#800000]"[/COLOR][/SIZE][SIZE=2], objConn)
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] objReader2 [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] OleDbDataReader
objReader2 = objCmd2.ExecuteReader
[/SIZE][SIZE=2][COLOR=#0000ff]While[/COLOR][/SIZE][SIZE=2] objReader2.Read
pc = (objReader2.GetString(9))
[/SIZE][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][SIZE=2] pc = [/SIZE][SIZE=2][COLOR=#800000]"Y"[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Then
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]ReDim[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Preserve[/COLOR][/SIZE][SIZE=2] Com(i)[/SIZE]
[SIZE=2][SIZE=2][COLOR=#0000ff]ReDim[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Preserve[/COLOR][/SIZE][SIZE=2] Comm(i) '<---------//[/SIZE]
[SIZE=2]
Comm(i).Nome = objReader2.GetString(2) [/SIZE][SIZE=2][COLOR=#008000]'Sede <-------//
[/COLOR][/SIZE][SIZE=2]Comm(i).Indirizzo = objReader2.GetString(4) [/SIZE][SIZE=2][COLOR=#008000]'indirizzo <---//
[/COLOR][/SIZE][SIZE=2]Comm(i).telefono = objReader2.GetString(5) [/SIZE][SIZE=2][COLOR=#008000]'telefono <-----//
[/COLOR][/SIZE][SIZE=2]Comm(i).Email = objReader2.GetString(8) [/SIZE][SIZE=2][COLOR=#008000]'email <------//
[/COLOR][/SIZE][SIZE=2]Comm(i).Cap = CapCom '<-----------------//
Comm(i).Comune = Comune '<-------------//
Comm(i).SiglaProvincia = Provincia '<-----------//
[/SIZE][/SIZE][SIZE=2]
i = i + 1
[/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]If
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]While
[/COLOR][/SIZE][SIZE=2]objConn.Close()
objConn.Dispose()
Com(0).NumeroComm = Com.Length '<------//
[/SIZE][SIZE=2][COLOR=#0000ff]For[/COLOR][/SIZE][SIZE=2] c = 0 [/SIZE][SIZE=2][COLOR=#0000ff]To[/COLOR][/SIZE][SIZE=2] Com.Length
[/SIZE][SIZE=2][COLOR=#0000ff]Return[/COLOR][/SIZE][SIZE=2] Com '<-----// I think this is the problem I must visualizze both result
[/SIZE][SIZE=2][COLOR=#0000ff]Next
[/COLOR][/SIZE][SIZE=2][COLOR=#008000]
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]If
 
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Function[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]
[/COLOR][/SIZE]

My result is this:

VB.NET:
 [COLOR=#0000ff]<?xml version="1.0" encoding="utf-8" ?>[/COLOR] 
[URL="http://localhost:2090/PsoapAccess/Service.asmx/SERVSUPP001#"][B][FONT=Courier New][COLOR=#ff0000]-[/COLOR][/FONT][/B][/URL] [COLOR=#0000ff]<[/COLOR][COLOR=#990000]ArrayOfSERVS1Result[/COLOR][COLOR=#ff0000] xmlns:xsi[/COLOR][COLOR=#0000ff]="[/COLOR][B][COLOR=#ff0000]http://www.w3.org/2001/XMLSchema-instance[/COLOR][/B][COLOR=#0000ff]" [/COLOR]
[COLOR=#ff0000] xmlns:xsd[/COLOR][COLOR=#0000ff]="[/COLOR][B][COLOR=#ff0000]http://www.w3.org/2001/XMLSchema[/COLOR][/B][COLOR=#0000ff]"[/COLOR]
[COLOR=#ff0000]x mlns[/COLOR][COLOR=#0000ff]="[/COLOR][B][COLOR=#ff0000]http://tempuri.org/[/COLOR][/B][COLOR=#0000ff]">[/COLOR]
[URL="http://localhost:2090/PsoapAccess/Service.asmx/SERVSUPP001#"][B][FONT=Courier New][COLOR=#ff0000]-[/COLOR][/FONT][/B][/URL] [COLOR=#0000ff]<[/COLOR][COLOR=#990000]SERVS1Result[/COLOR][COLOR=#0000ff]>[/COLOR]
 [COLOR=#0000ff]<[/COLOR][COLOR=#990000]NumeroComm[/COLOR][COLOR=#0000ff]>[/COLOR][B]3[/B][COLOR=#0000ff]</[/COLOR][COLOR=#990000]NumeroComm[/COLOR][COLOR=#0000ff]>[/COLOR] 
 [COLOR=#0000ff]<[/COLOR][COLOR=#990000]Comm[/COLOR] [COLOR=#0000ff]/>[/COLOR] 
 [COLOR=#0000ff]</[/COLOR][COLOR=#990000]SERVS1Result[/COLOR][COLOR=#0000ff]>[/COLOR]
 [COLOR=#0000ff]<[/COLOR][COLOR=#990000]SERVS1Result[/COLOR][COLOR=#0000ff]>[/COLOR]
 [COLOR=#0000ff]<[/COLOR][COLOR=#990000]NumeroComm[/COLOR][COLOR=#0000ff]>[/COLOR][B]0[/B][COLOR=#0000ff]</[/COLOR][COLOR=#990000]NumeroComm[/COLOR][COLOR=#0000ff]>[/COLOR] 
 [COLOR=#0000ff]<[/COLOR][COLOR=#990000]Comm[/COLOR] [COLOR=#0000ff]/>[/COLOR] 
 [COLOR=#0000ff]</[/COLOR][COLOR=#990000]SERVS1Result[/COLOR][COLOR=#0000ff]>[/COLOR]
[URL="http://localhost:2090/PsoapAccess/Service.asmx/SERVSUPP001#"][B][FONT=Courier New][COLOR=#ff0000]-[/COLOR][/FONT][/B][/URL] [COLOR=#0000ff]<[/COLOR][COLOR=#990000]SERVS1Result[/COLOR][COLOR=#0000ff]>[/COLOR]
 [COLOR=#0000ff]<[/COLOR][COLOR=#990000]NumeroComm[/COLOR][COLOR=#0000ff]>[/COLOR][B]0[/B][COLOR=#0000ff]</[/COLOR][COLOR=#990000]NumeroComm[/COLOR][COLOR=#0000ff]>[/COLOR] 
 [COLOR=#0000ff]<[/COLOR][COLOR=#990000]Comm[/COLOR] [COLOR=#0000ff]/>[/COLOR] 
 [COLOR=#0000ff]</[/COLOR][COLOR=#990000]SERVS1Result[/COLOR][COLOR=#0000ff]>[/COLOR]
 [COLOR=#0000ff]</[/COLOR][COLOR=#990000]ArrayOfSERVS1Result[/COLOR][COLOR=#0000ff]>[/COLOR]
 
The problem here is not how to pass a structure array through a web service, the problem lack of basic programming knowledge.

Why do you do this:
VB.NET:
Dim Com() As SERVS1Result 'Giusto
[COLOR=red]Dim Comm() As SERVS1Result.SComm '<---------//[/COLOR]
when you already have declared the Comm array to be a part of SERVS1Result structure...
VB.NET:
Public Structure SERVS1Result 'no this part
    Public NumeroComm As Integer 'no this part
[COLOR=darkgreen]    Public Comm() As SComm [/COLOR]
End Structure
Comm array is already part of SERVS1Result structure. That's what you asked about earlier, to extend the SERVS1Result structure to repeat the Comm part one time for each 'record'.

Why do you do:
VB.NET:
[COLOR=red]For c = 0 To Com.Length[/COLOR]
     Return Com
When function can only return once...

Why do you do:
VB.NET:
ReDim Preserve Comm[COLOR=red](i)[/COLOR]
When 'i' variable counts 0,1,2,3,4,5 etc. You quoted specification to be (0,1),(0,1),(0,1),(0,1) etc.
 
Yes basic programming knowledge is my problem.....
but if i try to use comm give me an error......
say me comm is not declare.....
 
that is because Comm is a member of Com instance of SERVS1Result.
JohnH said:
Either way you will then fill Com(i).Comm(0).member and Com(i).Comm(1).member.
 
I try this, forgive me if i don't understand :confused:

VB.NET:
[SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] Com() [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] SERVS1Result [/SIZE][SIZE=2][COLOR=#008000]'Giusto <----------//
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] pc [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]String
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] i [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Integer[/COLOR][/SIZE][SIZE=2] = 0
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] x [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Integer[/COLOR][/SIZE][SIZE=2] = 0
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] c [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Integer
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] objCmd2 [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] OleDbCommand([/SIZE][SIZE=2][COLOR=#800000]"Conn string[/COLOR][/SIZE][SIZE=2][COLOR=#800000]"[/COLOR][/SIZE][SIZE=2], objConn)
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] objReader2 [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] OleDbDataReader
objReader2 = objCmd2.ExecuteReader
[/SIZE][SIZE=2][COLOR=#0000ff]While[/COLOR][/SIZE][SIZE=2] objReader2.Read
pc = (objReader2.GetString(9))
[/SIZE][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][SIZE=2] pc = [/SIZE][SIZE=2][COLOR=#800000]"Y"[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Then
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]ReDim[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Preserve[/COLOR][/SIZE][SIZE=2] Com(0).Comm(i) '<--------//
Com(0).Comm(i).Nome = objReader2.GetString(2) [/SIZE][SIZE=2][COLOR=#008000]'Sede
[/COLOR][/SIZE][SIZE=2]Com(0).Comm(i).Indirizzo = objReader2.GetString(4) [/SIZE][SIZE=2][COLOR=#008000]'indirizzo
[/COLOR][/SIZE][SIZE=2]Com(0).Comm(i).telefono = objReader2.GetString(5) [/SIZE][SIZE=2][COLOR=#008000]'telefono
[/COLOR][/SIZE][SIZE=2]Com(0).Comm(i).Email = objReader2.GetString(8) [/SIZE][SIZE=2][COLOR=#008000]'email
[/COLOR][/SIZE][SIZE=2]Com(0).Comm(i).Cap = CapCom
Com(0).Comm(i).Comune = Comune
Com(0).Comm(i).SiglaProvincia = Provincia
i = i + 1
[/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]If
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]While
[/COLOR][/SIZE][SIZE=2]objConn.Close()
objConn.Dispose()
[/SIZE][COLOR=#008000][/COLOR][SIZE=2][COLOR=#008000]
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]Return[/COLOR][/SIZE][SIZE=2] Com
[/SIZE][SIZE=2][COLOR=#008000] 
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]If
[/COLOR][/SIZE]

this return to me the same first error :

System.NullReferenceException: reference to a object not import on a istance of a object in SERVS1ClassAccess.SERVS1(String ist)
 
Back
Top