0

I have data table which has columns namely Amount,StartDate. I am trying to get particular amount value from Amount based on StartDate.

My code is as follows:

DataTable dtt =_dstt.Tables[0];
var res = from r in dtt.AsEnumerable()
          where  r.Field("StartDate") == Convert.ToDateTime(drpStartYear.SelectedValue));
          select r.Field("Amount");

I am getting following error:

The type arguments for method 'System.Data.DataRowExtensions.Field(System.Data.DataRow, int)' cannot be inferred from the usage. Try specifying the type arguments explicitly.

_dsst is DataSet which I populate from database.

Is there better way to do it?

4

3 回答 3

3

这样做

DataTable dtt =_dstt.Tables[0];
var res = from r in dtt.AsEnumerable()
where  r.Field<DateTime>("StartDate") == Convert.ToDateTime(drpStartYear.SelectedValue));
select r.Field<Double>("Amount");

您需要像这样指定列的 DataTyper.Field<YourType>("ColumnName")

于 2013-06-17T08:53:39.837 回答
1
var res = from r in dtt.AsEnumerable()
          where  r.Field<DateTime>("StartDate") == Convert.ToDateTime(drpStartYear.SelectedValue));
          select r.Field<double>("Amount");
于 2013-06-17T08:53:27.537 回答
1
DataTable dtt =_dstt.Tables[0];
var res = from r in dtt.AsEnumerable()
          where  r.Field<type>("StartDate") == Convert.ToDateTime(drpStartYear.SelectedValue));
          select r.Field<type>("Amount");

type in <> 将是您正在使用的争论类型

于 2013-06-17T08:54:42.027 回答