Solved

LINQ doesnt accept DataTable

Posted on 2009-05-06
5
1,385 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

Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

820 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