?
Solved

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

Posted on 2008-06-24
3
Medium Priority
?
476 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 1000 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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

770 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