473,787 Members | 2,938 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How can I split database results with ExecuteReader and Split?

Hi, thanks for any help here:

SqlCommand cmd = new SqlCommand("SEL ECT categories FROM catalog"
conn);
rdr = cmd.ExecuteRead er();
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:Wom en'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:Wom en'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 1811
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***********@g mail.com wrote:
Hi, thanks for any help here:

SqlCommand cmd = new SqlCommand("SEL ECT categories FROM catalog"
conn);
rdr = cmd.ExecuteRead er();
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:Wom en'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:Wom en'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***********@g mail.com wrote:
Hi, thanks for any help here:

SqlCommand cmd = new SqlCommand("SEL ECT categories FROM catalog"
conn);
rdr = cmd.ExecuteRead er();
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:Wom en'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:Wom en'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
8062
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 a word when it encounters a space... so if possibly there is only a single space in the staring,then it shldnt be a problem isnt it? and also if there are more than 1 spaces then it says that also the word count would be 1 more than the total no...
9
1507
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 database independent by replacing the dll with whatever database is being supported. This would mean instead of returning SqlDataReaders another way to return results would have to be used. Is the best method to return database neutral...
3
1178
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 results of the search are displayed in a small datagrid. My problem is that I've no idea how to create the search functionality with VB.NET. The datadase used is a smal access database. Maybe one of you can give me a hint....
7
10626
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 Server 01 is brought back up? It still thinks it is the primary because that was its role when it crashed and it does not know about the takeover by force command that was issued. Does the 01 server check the 02 server to see what role they are in...
3
1495
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 want to run the action on different servers and mix the result at end and do the rest on the result.
6
2101
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 is wrong? using System; using System.Collections; using System.Collections.Generic;
12
3201
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(";"); MessageBox.Show(s);
3
2961
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 datatype for the file instead of using IMAGE datatype. I can not use SqlDataReader to read the data. I need your help, Thanks. -David (1) I have a table TestFile for testing: ID int FileName navrchar(255)
22
60289
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 provided the following as a quick example of how to retrieve data from a database. In order to connect to a SQL Server Database using .NET you will need to import the System.Data.SqlClient package into your program. If you are not connecting to a...
0
9655
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10363
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10172
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10110
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9964
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7517
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5398
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5535
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4069
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.