467,912 Members | 1,364 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,912 developers. It's quick & easy.

Return db record from a function - how?

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


Nov 19 '05 #1
  • viewed: 1529
Share:
5 Replies
Humm...you should have been able to find plenty of examples. since there
are a number of ways to go about it (depending on what your needs are), I'll
point you to a couple useful resources:

http://www.dotnetjunkies.com/quickst...ataaccess.aspx

http://www.asp101.com/articles/jay/a...et/default.asp

Hope this helps,
Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"D. Shane Fowlkes" <sh**********@h-o-t-m-a-i-l.com> wrote in message
news:uu******************@TK2MSFTNGP12.phx.gbl...
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

Nov 19 '05 #2
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?


"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
wrote in message news:OU****************@TK2MSFTNGP14.phx.gbl...
Humm...you should have been able to find plenty of examples. since there
are a number of ways to go about it (depending on what your needs are),
I'll
point you to a couple useful resources:

http://www.dotnetjunkies.com/quickst...ataaccess.aspx

http://www.asp101.com/articles/jay/a...et/default.asp

Hope this helps,
Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"D. Shane Fowlkes" <sh**********@h-o-t-m-a-i-l.com> wrote in message
news:uu******************@TK2MSFTNGP12.phx.gbl...
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


Nov 19 '05 #3
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/...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

--
MY ASP.Net tutorials
http://www.openmymind.net/
"D. Shane Fowlkes" <sh**********@h-o-t-m-a-i-l.com> wrote in message
news:u%********************@TK2MSFTNGP09.phx.gbl.. .
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?


"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
wrote in message news:OU****************@TK2MSFTNGP14.phx.gbl...
Humm...you should have been able to find plenty of examples. since there are a number of ways to go about it (depending on what your needs are),
I'll
point you to a couple useful resources:

http://www.dotnetjunkies.com/quickst...ataaccess.aspx

http://www.asp101.com/articles/jay/a...et/default.asp

Hope this helps,
Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"D. Shane Fowlkes" <sh**********@h-o-t-m-a-i-l.com> wrote in message
news:uu******************@TK2MSFTNGP12.phx.gbl...
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



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

"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
wrote in message news:O$**************@TK2MSFTNGP14.phx.gbl...
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/...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

--
MY ASP.Net tutorials
http://www.openmymind.net/
"D. Shane Fowlkes" <sh**********@h-o-t-m-a-i-l.com> wrote in message
news:u%********************@TK2MSFTNGP09.phx.gbl.. .
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?


"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
wrote in message news:OU****************@TK2MSFTNGP14.phx.gbl...
> Humm...you should have been able to find plenty of examples. since there > are a number of ways to go about it (depending on what your needs are),
> I'll
> point you to a couple useful resources:
>
> http://www.dotnetjunkies.com/quickst...ataaccess.aspx
>
> http://www.asp101.com/articles/jay/a...et/default.asp
>
> Hope this helps,
> Karl
>
> --
> MY ASP.Net tutorials
> http://www.openmymind.net/
>
>
> "D. Shane Fowlkes" <sh**********@h-o-t-m-a-i-l.com> wrote in message
> news:uu******************@TK2MSFTNGP12.phx.gbl...
>> 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
>>
>>
>>
>>
>
>



Nov 19 '05 #5
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

--
MY ASP.Net tutorials
http://www.openmymind.net/
"D. Shane Fowlkes" <sh**********@h-o-t-m-a-i-l.com> wrote in message
news:up**************@TK2MSFTNGP12.phx.gbl...
Yes! That's pointing me in the right direction. So have the Function
return an ArrayList? I'll look into that concept.....

"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
wrote in message news:O$**************@TK2MSFTNGP14.phx.gbl...
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/...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

--
MY ASP.Net tutorials
http://www.openmymind.net/
"D. Shane Fowlkes" <sh**********@h-o-t-m-a-i-l.com> wrote in message
news:u%********************@TK2MSFTNGP09.phx.gbl.. .
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?


"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
wrote in message news:OU****************@TK2MSFTNGP14.phx.gbl...
> Humm...you should have been able to find plenty of examples. since

there
> are a number of ways to go about it (depending on what your needs are), > I'll
> point you to a couple useful resources:
>
> http://www.dotnetjunkies.com/quickst...ataaccess.aspx >
> http://www.asp101.com/articles/jay/a...et/default.asp
>
> Hope this helps,
> Karl
>
> --
> MY ASP.Net tutorials
> http://www.openmymind.net/
>
>
> "D. Shane Fowlkes" <sh**********@h-o-t-m-a-i-l.com> wrote in message
> news:uu******************@TK2MSFTNGP12.phx.gbl...
>> 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
>>
>>
>>
>>
>
>



Nov 19 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

8 posts views Thread by Adrian Parker | last post: by
3 posts views Thread by Gunnar Liknes | last post: by
10 posts views Thread by Terry Lee Tucker | last post: by
2 posts views Thread by cantankerousoldgit | last post: by
reply views Thread by rajg78 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.