我想基於傳遞的列來獲取行的存在。該列作爲MultiSelect來自數據庫。LINQ - 指定的轉換不適用於dataview的使用
bool bCFPresent = IsMultiSelectCFPresent(dvDataTag, "MultiSelect");
public static bool IsPresent(DataView dvDataTag, string colName)
{
return ((from DataRowView drv in dvDataTag
where drv.Row.Field<short>(colName) == 1
select drv).Count() > 0 ? true : false);
}
但我收到此錯誤: -
System.InvalidCastException was unhandled by user code
Message="Specified cast is not valid." Source="System.Data.DataSetExtensions" StackTrace: at System.Data.DataRowExtensions.UnboxT`1.ValueField(Object value) at System.Data.DataRowExtensions.Field[T](DataRow row, String columnName)
請幫助。
什麼類型是 'COLNAME' 在DB? – 2011-05-04 12:04:55