472,791 Members | 1,566 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,791 software developers and data experts.

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 1721
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: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth

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.