hhjj
hhjj

Reputation: 31

How can I binde var variable to SqlDataSource?

I have this code:

var First_res = from r in reserve
                    join c in clerk on r.ClerkID equals c.ClerkID
                    select new { c.Name, c.Family, r.FoodID, r.Meal, r.Day };




    var Second_res = from fr in First_res
                     join f in food on fr.FoodID equals f.FoodID
                     select new { fr.Name, fr.Family, fr.Meal, fr.Day, food = f.Name };

now I want to bind Second_res to SqlDataSource, but when I write below code, I have error:

SqlDataSource1.DataSourceMode = Second_res;

How can I do it? this is my error: Cannot implicitly convert type 'System.Linq.Iqueryable' to 'System.Web.UI.WebControls.SqlDataSourceMode'

Upvotes: 0

Views: 108

Answers (1)

user1429080
user1429080

Reputation: 9166

SqlDataSource doesn't have/take a data source. Rather it is a data source.

Do you have a GridView, a Listview or a similar databound control where you want to show thr data?

Assign the data to the datasource property on that control instead and then call databind on it.

Upvotes: 1

Related Questions