Solved

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

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Calling web service and its methods dynamically 2 43
C# Offline Apllication 5 56
Error on Add method 1 38
Help with C#, MVC, razor. 6 23
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
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!
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

863 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

22 Experts available now in Live!

Get 1:1 Help Now