How can I split database results with ExecuteReader and Split?

N

needin4mation

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.
 
?

=?ISO-8859-1?Q?G=F6ran_Andersson?=

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.
 
N

needin4mation

I inherited it. I have no choice, but to split it up.

Thanks for your help.

Göran Andersson said:
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.

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,734
Messages
2,569,441
Members
44,832
Latest member
GlennSmall

Latest Threads

Top