Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > How can I split database results with ExecuteReader and Split?

Reply
Thread Tools

How can I split database results with ExecuteReader and Split?

 
 
needin4mation@gmail.com
Guest
Posts: n/a
 
      05-03-2006
Hi, thanks for any help here:

SqlCommand cmd = new SqlCommand("SELECT categories FROM catalog"
conn);
rdr = cmd.ExecuteReader();
String temp;
while (rdr.Read())
{
temp = rdr[0];
Response.Write(temp.Split(":"));
}

Doesn't work. I get can't convert object to string, and I'm not real
sure I right here anyway. I think I need another function.

I have a category column in my database that looks like this:

column1
------------
Accessories:Women's Socks:Women's Socks - Athletic

It is a colon delimited list in the column. Now I have to split it
back up. Can anyone tell me how to split that column when I retrieve
that row? Do I send:

Accessories:Women's Socks:Women's Socks - Athletic

to another function where it iterates through each value (to do
whatever it is I need done)? Thanks for any help.

 
Reply With Quote
 
 
 
 
=?ISO-8859-1?Q?G=F6ran_Andersson?=
Guest
Posts: n/a
 
      05-04-2006
You either have to cast the object to string, or use the GetString
method to get the value as a string:

temp = rdr.GetString(0);

Generally it's a bad idea to store several values in a single field in
the database, though. Which ever way you use the values, you always have
to go through the process of breaking the string up before you can use
the values. Actually using the values in a query is near impossible to do.

http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> Hi, thanks for any help here:
>
> SqlCommand cmd = new SqlCommand("SELECT categories FROM catalog"
> conn);
> rdr = cmd.ExecuteReader();
> String temp;
> while (rdr.Read())
> {
> temp = rdr[0];
> Response.Write(temp.Split(":"));
> }
>
> Doesn't work. I get can't convert object to string, and I'm not real
> sure I right here anyway. I think I need another function.
>
> I have a category column in my database that looks like this:
>
> column1
> ------------
> Accessories:Women's Socks:Women's Socks - Athletic
>
> It is a colon delimited list in the column. Now I have to split it
> back up. Can anyone tell me how to split that column when I retrieve
> that row? Do I send:
>
> Accessories:Women's Socks:Women's Socks - Athletic
>
> to another function where it iterates through each value (to do
> whatever it is I need done)? Thanks for any help.
>

 
Reply With Quote
 
 
 
 
needin4mation@gmail.com
Guest
Posts: n/a
 
      05-05-2006
I inherited it. I have no choice, but to split it up.

Thanks for your help.

Göran Andersson wrote:
> You either have to cast the object to string, or use the GetString
> method to get the value as a string:
>
> temp = rdr.GetString(0);
>
> Generally it's a bad idea to store several values in a single field in
> the database, though. Which ever way you use the values, you always have
> to go through the process of breaking the string up before you can use
> the values. Actually using the values in a query is near impossible to do.
>
> (E-Mail Removed) wrote:
> > Hi, thanks for any help here:
> >
> > SqlCommand cmd = new SqlCommand("SELECT categories FROM catalog"
> > conn);
> > rdr = cmd.ExecuteReader();
> > String temp;
> > while (rdr.Read())
> > {
> > temp = rdr[0];
> > Response.Write(temp.Split(":"));
> > }
> >
> > Doesn't work. I get can't convert object to string, and I'm not real
> > sure I right here anyway. I think I need another function.
> >
> > I have a category column in my database that looks like this:
> >
> > column1
> > ------------
> > Accessories:Women's Socks:Women's Socks - Athletic
> >
> > It is a colon delimited list in the column. Now I have to split it
> > back up. Can anyone tell me how to split that column when I retrieve
> > that row? Do I send:
> >
> > Accessories:Women's Socks:Women's Socks - Athletic
> >
> > to another function where it iterates through each value (to do
> > whatever it is I need done)? Thanks for any help.
> >


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
ExecuteReader: Connection property has not been initialized MattB ASP .Net 3 10-04-2007 08:09 AM
ExecuteReader requires an open and available Connection. =?Utf-8?B?TWlrZQ==?= ASP .Net 6 09-12-2006 08:52 PM
Odd ExecuteReader Error JD Drewes ASP .Net 0 10-28-2003 08:18 PM
"Executereader requires an open and available connection" error karim ASP .Net 6 08-14-2003 10:11 PM
"Internal connection fatal error" when calling SQLCommand.ExecuteReader Julian Bowes ASP .Net 0 07-01-2003 10:46 AM



Advertisments