简体   繁体   English

如何使用 LINQ 和 FillDataSet(ds) 方法填充数据集 c#

[英]How to fill dataset using LINQ with FillDataSet(ds) Method c#

How to fill dataset using LINQ with FillDataSet(ds) Method.如何使用 LINQ 和 FillDataSet(ds) 方法填充数据集。 When iam trying to implement this code iam getting error like FillDataSet does not exist in current context.当我尝试实现此代码时,我收到错误,例如当前上下文中不存在 FillDataSet。

My code is我的代码是

DataSet ds = new DataSet();
ds.Locale = CultureInfo.InvariantCulture;
FillDataSet(ds);

DataTable products = ds.Tables["emp"];

IEnumerable<DataRow> query =
    from product in dtContext.emps.AsEnumerable()
    select product;

Please tell me how to fill dataset with FillDataSet(ds) Method.请告诉我如何使用 FillDataSet(ds) 方法填充数据集。 Thank you.谢谢你。

You don't have to fill a DataSet with LINQ2SQL.不必填充DataSet与LINQ2SQL。 Nor do you have to use DataTable etc. All you need is the data context and perform queries on that:您也不必使用DataTable等。您只需要数据上下文并对其执行查询:

var query = from product in dtContext.emps
            select product;

query will be of type IQueryable<T> and you can use eg a foreach on it to go through its content, or filter it further with a where clause. query将是IQueryable<T>类型,您可以在其上使用例如foreach来查看其内容,或使用where子句对其进行进一步过滤。 Why do you want a DataSet ?你为什么需要一个DataSet

You have to define your FillDataSet(DatatSet ds) method.您必须定义FillDataSet(DatatSet ds)方法。 Probably you should implement something similar to this example if you are following the MSDN tutorials.如果您遵循 MSDN 教程,您可能应该实现与此示例类似的内容。

From your post从你的帖子

FillDataSet does not exist in current context.当前上下文中不存在 FillDataSet。

It clearly means that it cant access the FillDataSet method or else your method doesnt exist.这显然意味着它无法访问 FillDataSet 方法,否则您的方法不存在。

If it exists, then try changing the access specifier to public if it is in different class.如果它存在,然后尝试将访问说明符更改为public如果它在不同的类中。

PS: did you declare any method named FillDataSet ? PS:您是否声明了任何名为FillDataSet方法?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM