473,467 Members | 1,602 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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
5 1754
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Adrian Parker | last post by:
Hi. I would like to query a database, given several where clauses to refine my search, and return the value of one single field in the database. eg: I have a table that lists teachers. Their...
2
by: Alexander Pino | last post by:
Hi, does anyone know if, and how, I can return a record (set) from a stored procedure/function? What does the function have to do? well at this moment I'm porting our product's database based...
3
by: Gunnar Liknes | last post by:
Hi, Is it possible to make a stored procedure or function to generate a return value? I have a stored procedure which inserts a new row in a table. I would like that proceudre to return the...
20
by: MS | last post by:
Access 97 I want to requery the data being displayed on a form, then I want to return to the record I was in. Why doesn't this code work? Private Sub CmdRefsh_Click()
10
by: Terry Lee Tucker | last post by:
I need to return a row of data from a function. I've been looking the the HTML docs and have found nothing of value. If I try to return a variable of type RECORD, I get the following error:...
1
by: David | last post by:
Hi, I have a problem with returning a value from an external function..... My asp page is basically a list taken from a database. A date record is written from the DB, then all the...
2
by: cantankerousoldgit | last post by:
I am trying to call a DLL with a function like this: """DESCRIPTION: Get a list of objects attributes matching attribute values ARGUMENTS: session : the current session classId :...
0
by: rajg78 | last post by:
Hi All, First time I am posting, so please forgive me if I miss out any information while asking you my question. I have a .net web app that I am building in 2.0 framework. I have a code-behind...
6
by: SethM | last post by:
I have a stored procedure that returns a record set. I want to functionalize this so I can have multiple presentations of the same record set. However, I can not get rs_event.open StoreProc to pass...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.