Solved

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

Posted on 2008-06-24
3
475 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

724 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