-
Converting a recordset to a string or how to access the entire recordset at once
Hello,
All of the code I have found for getting the results of a recordset from
a database query involve either retrieving a single record based on the count
or and index value.
In most cases that is fine, but I need it as a comma delimited list.
Is there a simple way of retrieving the entire record set (a single field
from the query of course)?
For instance, given a database table called MaxLookupID that has two fields,
ID and MaxLookupID, I run a query that grabs all of the data from the 2 fields.
I need all of the values from the MaxLookupID in a list.
I don't want to concatinate the recordset if I don't have to.
It seems likely that there is a simple way to do this, but I haven't been
able to find it.
Best regards,
Illyana Rasputin
-
Re: Converting a recordset to a string or how to access the entire recordset at once
Ooops. I messed up on the original subject line. I didn't describe the issue
very well. Sorry.
Best regards,
Illyana Rasputin
"Illyana Rasputin" <illyana888@hotmail.com> wrote:
>
>Hello,
>
>All of the code I have found for getting the results of a recordset from
>a database query involve either retrieving a single record based on the
count
>or and index value.
>
>In most cases that is fine, but I need it as a comma delimited list.
>
>Is there a simple way of retrieving the entire record set (a single field
>from the query of course)?
>
>For instance, given a database table called MaxLookupID that has two fields,
>ID and MaxLookupID, I run a query that grabs all of the data from the 2
fields.
> I need all of the values from the MaxLookupID in a list.
>
>I don't want to concatinate the recordset if I don't have to.
>
>It seems likely that there is a simple way to do this, but I haven't been
>able to find it.
>
>Best regards,
>Illyana Rasputin
-
Re: Converting a recordset to a string or how to access the entire recordset at once
Sorry, I just realized that I forgot to mention that I am using "System.Data.OleDb'
for the connection (I think that might affect what classes can be used, but
I wasn't sure).
Best regards,
Illyana Rasputin
"Illyana Rasputin" <illyana888@hotmail.com> wrote:
>
>Ooops. I messed up on the original subject line. I didn't describe the
issue
>very well. Sorry.
>
>Best regards,
>Illyana Rasputin
>
>"Illyana Rasputin" <illyana888@hotmail.com> wrote:
>>
>>Hello,
>>
>>All of the code I have found for getting the results of a recordset from
>>a database query involve either retrieving a single record based on the
>count
>>or and index value.
>>
>>In most cases that is fine, but I need it as a comma delimited list.
>>
>>Is there a simple way of retrieving the entire record set (a single field
>>from the query of course)?
>>
>>For instance, given a database table called MaxLookupID that has two fields,
>>ID and MaxLookupID, I run a query that grabs all of the data from the 2
>fields.
>> I need all of the values from the MaxLookupID in a list.
>>
>>I don't want to concatinate the recordset if I don't have to.
>>
>>It seems likely that there is a simple way to do this, but I haven't been
>>able to find it.
>>
>>Best regards,
>>Illyana Rasputin
>
-
Re: Converting a recordset to a string or how to access the entire recordset at once
> Is there a simple way of retrieving the entire recordset...
> [in a comma-delimited list]?
Illyana: Here's how I would do it (Warning: Air code written by a VB guy,
but you'll get the idea):
OleDbDataReader dr;
ArrayList al = New ArrayList();
// Retrieve query results into DataReader
// Loop through DataReader, adding desired
// column to ArrayList
while (dr.Read)
{
al.Add(dr["MaxLookupID"]);
}
dr.Close()
// Now use Join function to create comma-
// delimited string
String delimList = Join(al.ToArray, ", ");
--
Phil Weber
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks