Prash's Blog

Cannot convert lambda expression to type ‘string’ because it is not a delegate type November 7, 2011

Filed under: ADO — prazjain @ 12:34 pm
Tags: , , , , ,

This error happens over and over but only after considerable time when you have forgotten how you fixed it last time.

            foreach (string colName in breakup)
            {
                IEnumerable res = from row in QueryCSVModel.FilteredData.Table
                                  select row[colName];    //error on select : Cannot convert lambda expression to type 'string' because it is not a delegate type
                //do something here
            }

This is the solution specified here  (rewriting here in case it helps you)

  • Add reference to System.Data.DataSetExtensions
  • Add using for System.Data and System.Linq

But this still did not work for me.

What I missed is using AsEnumerable() after DataTable, this code below works

            foreach (string colName in breakup)
            {
                IEnumerable res = from row in QueryCSVModel.FilteredData.Table.AsEnumerable()
                                  select row[colName];
                //do something here
            }
Advertisements
 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s