Solved

LINQ doesnt accept DataTable

Posted on 2009-05-06
5
1,380 Views
Last Modified: 2013-11-11
I have this code: (ds is DataSet)

DataTable dtRawData = ds.Tables[0];

        int iStateIDX = 1;

        for (int i = 0; i < dtRawData.Rows.Count; i++, iStateIDX++)
LINQ doesnt accept this code, because I can not implement AsEnumerable  in DataTable dtRawData = ds.Tables[0].AsEnumerable; it is an error
I can use only row collection
var rows = from p in ds.Tables[0].AsEnumerable()
foreach (var v in rows)
I need to use "int I" , but I cannot put rows.Count instead of dtRawData.Rows.Count in this statement:
for (int i = 0; i < dtRawData.Rows.Count; i++, iStateIDX++), it is an error
How can I use Data Table for LINQ, or insert rows.Count im this statement?

0
Comment
Question by:J_Kogan
5 Comments
 
LVL 9

Expert Comment

by:tculler
ID: 24319858
Remember, there are two types of DataTables-- System.Linq.DataTable, and System.Data.DataTable. Which are you using? The System.Linq one? Because that one is generic, and requires generic type parameters. I'm at school, so I can't test it (we're running the .NET Framework 2.0 right now, 'cuz the administration is severely disabled in EVERY way known to man).

Anyways, if you're using linq, you need to use its DataTable object. I believe it look ssomething like this...
System.Linq.DataTable<typeOfObjectsInTable> linqTable =

     new System.Linq.DataTable<typeOfObjectsInTable>();

Open in new window

0
 

Author Comment

by:J_Kogan
ID: 24320138
I use System.Data.DataTable, may I use another one?
will be better?
0
 
LVL 9

Expert Comment

by:tculler
ID: 24320602
You must use the Linq table type in your Linq statements. Otherwise, you're intermixing these two objects with totally different implementations.
0
 
LVL 9

Accepted Solution

by:
Sreedhar Vengala earned 250 total points
ID: 24322093
0
 

Expert Comment

by:ekekakos
ID: 24779460
As I found today the following I hope that will help you



Dim OrderedMaterials = From Material In DatasetPurchases.Tables("SelectMaterialsPacking").AsEnumerable(), _

PurchasedMaterial In DatasetPurchases.Tables("PurchaseMaterials").AsEnumerable() _

Where PurchasedMaterial!MaterialID_FK = Material!MaterialID And _

PurchasedMaterial!PurchaseID_FK = ListBoxControlPurchases.SelectedValue _

Select Material!MaterialID, Material!MaterialMnemonic, Material!MaterialDescription, Material!PackingMnemonic

Open in new window

0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now