我试图使用LINQ行从列值遍历在一个DataTable,并实例化对象。下面显示了棘手的代码。“无法解析符号选择”尝试使用LINQ与DataRowCollection
的问题是,代码将无法编译。恶意错误消息是“无法解析符号选择”。我很满意DataRowCollection实现IEnumerable(它从System.Data.InternalDataCollectionBase中获取它),所以你会认为下面没有问题(显然,我错了那个计数)。
我已经包含System.Linq的System.Data和System.Data.SqlClient在我的项目。它也有所有必要的参考。我之前一直在使用LINQ(主要是使用POCO和XDocuemnts列表),这是我第一次看到这个特定的消息。
如何解决它有什么建议?
using (var command = connection.CreateCommand())
{
command.CommandText = "dbo.sp_pTicklerContacts_sel_W_ContactRole_by_ComKey";
command.CommandTimeout = 120;
command.CommandType = CommandType.StoredProcedure;
command.Parameters.Add("@iComKey", SqlDbType.Int).Value = companyKey;
using (var adapter = new SqlDataAdapter(command))
{
var dataset = new DataSet();
adapter.Fill(dataset);
if (dataset.TableCount() > 0 && dataset.Tables[0].Rows.Count > 0)
{
return (from row in dataset.Tables[0].Rows
select new TicklerContact
{
CompanyKey = row.ToInt32("iTicklerContact"),
Contact = row.ToString("ccontact"),
ContactKey = row.ToInt32("iconkey"),
TicklerContactKey = row.ToInt32("iTicklerContactKey"),
Role = row.ToString("contactrole"),
Exists = row.ToBool("contactexists")
}).ToList();
}
return null;
}
}
你得到一个线突出显示错误消息? – 2011-01-12 18:45:28