Solved

Best way to get a single row

Posted on 2004-08-08
5
246 Views
Last Modified: 2012-03-15
Hi, if I have a stored procedure that when executed will return one row, with three columns, what is the best way to get the data from this. At the mo I have a sqldataadapter filling a dataset, but ho do I get the data from there, I want three vars say v1,v2 and v3 to be populated with the string vals in the row?

Thanks Kieran.
0
Comment
Question by:kplonk
[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
5 Comments
 
LVL 37

Accepted Solution

by:
gregoryyoung earned 20 total points
ID: 11747590
DataAdapter.Fill(yourDataSet, "tablename");

if(yourDataSet.Tables["tablename"].Rows.Count == 1) {
    DataRow dr = yourDataSet.Tables["tablename"].Rows[0];
    //here you can access variables like dr["name"] ...
}

given that you only return 3 values you might want to look at output parameters from your stored procedure.
0
 
LVL 15

Expert Comment

by:Timbo87
ID: 11747733
Even a DataAdapter and DataSet may be a bit overkill. If you're just reading the data and not updating it, a DataReader should do the job.

string col1, col2, col3;
SqlCommand cmd = new SqlCommand("storedProcedure", connectionObject);
cmd.CommandType = CommandType.StoredProcedure;
connectionObject.Open();
SqlDataReader dr = cmd.ExecuteReader();
dr.Read();
col1 = dr.GetString(0);
col2 = dr.GetString(1);
col3 = dr.GetString(2);
dr.Close();
connectionObject.Close();
0
 
LVL 9

Expert Comment

by:s_sansanwal
ID: 11748015
0
 

Author Comment

by:kplonk
ID: 11748180
Thanks just what i wanted
0
 
LVL 37

Expert Comment

by:gregoryyoung
ID: 11748227
Anytime. Glad to help.

Cheers,

Greg
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
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.

710 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