473,386 Members | 1,819 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

How can I split database results with ExecuteReader and Split?

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.

May 3 '06 #1
2 1794
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.

ne***********@gmail.com 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.

May 4 '06 #2
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.

ne***********@gmail.com 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.


May 5 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: mehul | last post by:
hi all, i am just starting with PERL and had this doubt related to the speical operator +. what it says is that in the line split( / +/,$line); it will not ignore the initial spaces as it starts...
9
by: shadow.demon | last post by:
G'day, I've separated my database calls into a separate dll, and return results from any database calls as a SqlDataReader (because of SQL Server use, it's nice and fast). However I'd like to be...
3
by: Animal | last post by:
Hey, I've got the following problem: I'm trying to create a small tool that must be able to search thrue a database using a search-criteria, that has to be entered by the user in a TextBox. The...
7
by: Mark A | last post by:
If server 01 running HADR in the primary role crashes, and the DBA does a HADR takeover by force on the 02 server to switch roles, then the 02 server is now the primary. What happens when the...
3
by: Venkat | last post by:
Hi, Ours is a windows based application and I have to perform an action which takes much time (as it requires much CPU time) on a single pc. I want to split the action to more than two and I...
6
by: axel22 | last post by:
I have added a new SQL database into my project, added a table manually in VS IDE, and then I've run the following code that always results in an exception? Could it be that the connection string...
12
by: garyusenet | last post by:
string lines = File.ReadAllLines(@"c:\text\history.txt"); foreach (string s in lines) { ArrayList results = new ArrayList(); string delimit = ";"; string currentline = s.Split(";"); ...
3
by: =?Utf-8?B?ZGF2aWQ=?= | last post by:
I try to follow Steve's paper to build a database, and store a small text file into SQL Server database and retrieve it later. Only difference between my table and Steve's table is that I use NTEXT...
22
Frinavale
by: Frinavale | last post by:
How To Use A Database In Your Program Many .NET solutions are database driven and so many of us often wonder how to access the database. To help you understand the answer to this question I've...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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...

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.