Solved

Passing value of select statement to variables using asp.net c#

Posted on 2008-06-24
3
470 Views
Last Modified: 2013-11-07
I have a sql statement like this
select name,phonenumber,address from
infor where id=7898

I will like to execute this statement
and store the values  of name, phonenumber and
address in 3 variables.

How can I achieve this?

Thanks.

0
Comment
Question by:Sirdots
  • 2
3 Comments
 
LVL 18

Expert Comment

by:philipjonathan
ID: 21862186
If what you mean is how to retrieve data from database, you can use SqlDataReader or SqlDataAdapter. Here's a link:
http://www.codeproject.com/KB/aspnet/RetrieveMoreData.aspx
0
 

Author Comment

by:Sirdots
ID: 21862213
Thanks philipjonathan. This is not what I mean. I can retrieve value from database. what i mean is how do I store the individual values I receive in different variables

select name,phonenumber,address from
infor where id=7898

example
variable1 = name
variable2 = phonenumber
variable3 = address.
0
 
LVL 18

Accepted Solution

by:
philipjonathan earned 250 total points
ID: 21862848
Alright, is your question asking more from design point of view or simply how to do it?
If the first, then it really depends on the context of your application, you'd need to tell me more. If the second, and supposing you use SqlDataReader:

SqlDataReader reader = cmd.ExecuteReader();

if (reader.Read())

{

  string name = (string) reader["name"];

  string phoneNumber = (string) reader["phonenumber"];

  string address = (string) reader["address"];

}

Open in new window

0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now