Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

LINQ doesnt accept DataTable

Posted on 2009-05-06
5
Medium Priority
?
1,393 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 1000 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

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

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

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Hello there! As a developer I have modified and refactored the unit tests which was written by fellow developers in the past. On the course, I have gone through various misconceptions and technical challenges when it comes to implementation. I would…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Loops Section Overview
Suggested Courses

783 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