?
Solved

LINQ doesnt accept DataTable

Posted on 2009-05-06
5
Medium Priority
?
1,390 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

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.
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

718 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