Return db record from a function - how?

D

D. Shane Fowlkes

This may be a very basic question but it's something I've never done before.
I've looked at a couple of my favorite sites and books and can't find an
answer either. I can write a Function to return a single value. No big
deal. But I want to call a Function from another Sub and the function finds
and returns an entire db record. Using ASP.NET (VB!), how can this be done
and how can I differentiate between the fields/columns?

For example:

My Sub()
Dim X As what? String? DataReader?

...do stuff....
X = MyFunction()
...do more stuff using the valueS stored in X
End Sub



My Function() As What? String? DataReader?
....go find record in db and return all fields
End Function


Thanks
-S
 
D

D. Shane Fowlkes

Thanks but I was hoping to get help on my specific issue. I know to connect
to a db and retrieve records and bind them if needed. But I'm not really
sure how to return the data from the record from the function itself. It's
a very basic question really. A Function returns A single value right? So
how can I use a Function to return a db record and the record contains
multiple fields/columns? Do I have the function return an "Object" instead
of a String? If so, in my Sub that calls the function, how can I tell what
field is what in the object? Thanks

Make sense?
 
D

D. Shane Fowlkes

Yes! That's pointing me in the right direction. So have the Function
return an ArrayList? I'll look into that concept.....
 
K

Karl Seguin

Sorry,
Generally you'd return the datatable or dataset....it can be tricky to
return a datareader since it requires the connection to remain open (so
who's responsible for closing it?). (I think it's better to use custom
entities (http://weblogs.asp.net/plip/archive/2004/04/11/111128.aspx) but
that might be a little too much right now).

A single value can hold multiple values....a single value isn't
necessarilily a string or an int. ArrayLists for example can hold X
objects, hashtables the same, DataSets and DataTables hold multiple
values...though they are a single object.

Karl
 
K

Karl Seguin

No..have it return a datatable :)

I was just saying that just because something is a single object doens't
mean it can't hold multiple values. If you have a single column, arraylist
might be good..but if you are holding on to multiple
columns/rows...datatable/dataset will be easiest..

Karl
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top