Vara Prasad.M
Vara Prasad.M

Reputation: 1550

Get the column Value using Linq from dataset in c#

In the Linq after retrieving from the dataset how can i get the column data without using the for each statement?

 var query = from alias in ds.Tables[0].AsEnumerable()
                        where alias.Field<string>("lanename") == ddlLaneController.SelectedItem.Text
                        select new
                        {
                            locname = alias["LocationName"],
                            locid = alias["locationid"]
                        };

txtStartLocation.Text = query.Select(a => a["LocationName"]).ToString();

Can i know how can i achieve this?

Thanks, Vara Prasad

Upvotes: 0

Views: 3289

Answers (2)

ionden
ionden

Reputation: 12776

If there is a single resulting row use Single:

txtStartLocation.Text = query.Single().locname;

Upvotes: 2

Daniel Hilgarth
Daniel Hilgarth

Reputation: 174309

I think you want to use First():

txtStartLocation.Text = query.First().locname.ToString();

Upvotes: 1

Related Questions