Solved

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

Posted on 2008-06-24
3
474 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

MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

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…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

732 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