Reputation: 4732
var results = from myRow in dsPac.AsEnumerable()
where myRow.Field<string>("Package_Name").Equals(lblPackageName.Text)
select myRow;
The dsPac
contains
I want to select data corresponding to Package1712200466
ie
When I bind to a GridView I get the following error
DataBinding: 'System.Data.DataRow' does not contain a property
with the name 'Holiday_ID'.
Upvotes: 1
Views: 1819
Reputation: 42991
Alternatively you can use AsDataView() to convert the row collection back to a DataView which the GridView will be able to bind to.
var results = (from myRow in dsPac.AsEnumerable()
where myRow.Field<string>("Package_Name").Equals(lblPackageName.Text)
select myRow).AsDataView();
Upvotes: 3
Reputation: 16167
In the past when I have data rows that I wish to bind into a GridView, I create an object to do so. In this case, you could probably use your Linq query to create an anonymous object that will do the trick.
var results = from myRow in dsPac.AsEnumerable()
where myRow.Field<string>("Package_Name").Equals(lblPackageName.Text)
select new { Holiday_ID = myRow["Holiday_ID"],
Holiday_Description = myRow["Holiday_Description"],
Holiday_Date = myRow["Holiday_Date"] };
I don't believe biding to the row directly will work - see the exception text. Row columns are accessed via an Item[] indexer, so you would need to write a WPF converter to achieve the same effect. In all, a waste of time because the Linq query will work.
Upvotes: 5