Solved

LINQ doesnt accept DataTable

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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

632 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