Link to home
Start Free TrialLog in
Avatar of kplonk
kplonk

asked on

Best way to get a single row

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.
ASKER CERTIFIED SOLUTION
Avatar of gregoryyoung
gregoryyoung
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Timbo87
Timbo87

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();
Avatar of kplonk

ASKER

Thanks just what i wanted
Anytime. Glad to help.

Cheers,

Greg