Error passing dataset by ref

  • Thread starter Thread starter Wes Hutton via .NET 247
  • Start date Start date
W

Wes Hutton via .NET 247

I am trying to pass a data object (set or row) into a functionbyref, and have the same issue either way. In the maincontroller function, I have no issues accessing any parts of mydataset. If I extract a data row, it has values and is fine. However, when I pass either the whole dataset or just a data rowto another function, it errors out, and in the Locals windowjust has "error: cannot obtain value" against every field. I'vecopied the code from another class where it works perfectly, cananyone suggest why it all of a sudden won't let me pass thedataset or components of the dataset successfully? Also, oncethis problem occurs, .NET won't let me set the next statementeither.

thanks for your help.

Sample code:

public sub controller()
<get the data here>

'this line works fine
dim intID as integer = objDataSet.Company(0).IDCompany

'now pass the dataset to the function
MapCompany(objDataSet) 'at this point dataset can beaccessed completely
end sub

private sub MapCompany(ByRef objDataset as CompanyDataset) asCompany
'at this point the data cannot be read any more
dim intID as integer = objDataset.Company(0).IDCompany
end sub
 
Add a try-catch block to see what the error is...

private sub MapCompany(ByRef objDataset as CompanyDataset) ' as Company <--
sub can't have return values
'at this point the data cannot be read any more
try
dim intID as integer = objDataset.Company(0).IDCompany
catch ex as exception
msgbox(ex.tostring)
debug.writeline(ex.tostring)
end try
end sub

Let us know exactly what the exception is you are getting...

Greg

I am trying to pass a data object (set or row) into a function byref, and
have the same issue either way. In the main controller function, I have no
issues accessing any parts of my dataset. If I extract a data row, it has
values and is fine. However, when I pass either the whole dataset or just a
data row to another function, it errors out, and in the Locals window just
has "error: cannot obtain value" against every field. I've copied the code
from another class where it works perfectly, can anyone suggest why it all
of a sudden won't let me pass the dataset or components of the dataset
successfully? Also, once this problem occurs, .NET won't let me set the
next statement either.

thanks for your help.

Sample code:

public sub controller()
<get the data here>

'this line works fine
dim intID as integer = objDataSet.Company(0).IDCompany

'now pass the dataset to the function
MapCompany(objDataSet) 'at this point dataset can be accessed
completely
end sub

private sub MapCompany(ByRef objDataset as CompanyDataset) as Company
'at this point the data cannot be read any more
dim intID as integer = objDataset.Company(0).IDCompany
end sub
 
Back
Top