Welcome to Dream.In.Code
Getting C# Help is Easy!

Join 132,111 C# Programmers for FREE! Get instant access to thousands of C# experts, tutorials, code snippets, and more! There are 2,088 people online right now. Registration is fast and FREE... Join Now!




Retrieve single string from MySQL db

 
Reply to this topicStart new topic

Retrieve single string from MySQL db

fooboo
post 7 Oct, 2008 - 07:40 AM
Post #1


The king of Nynex

Group Icon
Joined: 28 Jul, 2006
Posts: 2,832



Thanked 1 times

Dream Kudos: 150
My Contributions


Using VS 2005:

I have forgotten how to do something really simple. In my defense I have a rotten head cold so I can barely operate door handles and the like at this point but it also seems to have emptied my head of all programming ability.

I need to query a MySQL db using a key that I provide and I want it to return a single string.
I have the key and the query sorted, the data is there in the db.
I can use the data adapter to fill a data set or data table.

What I can't remember how to do is use the returned data as a string (and ToString() doesn't do the trick).

The query basically looks up url in a table, I provide a key code like "home" or "admin" etc. and it returns "~/index.aspx" or something similar.

What I can't get my head round in my muddled state is how I get that single string. I don't want a table or a set of data I just want to send a query to the db and have it return a string that I can then use to redirect to.

Any pointers would be great.

User is online!Profile CardPM

Go to the top of the page

fooboo
post 8 Oct, 2008 - 12:49 AM
Post #2


The king of Nynex

Group Icon
Joined: 28 Jul, 2006
Posts: 2,832



Thanked 1 times

Dream Kudos: 150
My Contributions


Hmm so nobody else knows how to do this either?
User is online!Profile CardPM

Go to the top of the page

fooboo
post 8 Oct, 2008 - 03:24 AM
Post #3


The king of Nynex

Group Icon
Joined: 28 Jul, 2006
Posts: 2,832



Thanked 1 times

Dream Kudos: 150
My Contributions


In case anyone is having the same problem, my colleague returned from his day off and solved this one straight away.
It's so embarrassingly simple, I have even used this exact method elsewhere in my code but in my brain funk I just couldn't remember it.
It's ExecuteScalar I'm using it like this:
CODE
MySqlCommand geturl = new MySqlCommand(stB.ToString(), con.cnn);
object objUrl = geturl.ExecuteScalar();
string there = objUrl.ToString();


I hope that helps someone as some sort of karmic payback for me being so brain dead at the mo.

(stB.ToString() is just a string builder I'm using to create the MySQL command rather than a straight string variable and con.cnn is an instance of my connection object)
User is online!Profile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 11/21/08 10:02AM

Live C# Help!

C# Tutorials

Reference Sheets

C# Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month