Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# SQL LINQ SQL-Server-2008 , +
I try it by using datatable like that
 
for (int i = 0; i < dtp.Rows.Count; i++)
            {
                if (dtp.Rows[i]["UserId"].ToString() == formid.ToString())
              {
                   
              }
           }
 
Now I need it but by using LINQ How can I loop linq query
 
my linq query like that
 
int ID = (from s in con.TUsers
                                    where s.UserId.Equals(comboBox1.SelectedValue)
                                    select s.UserId).SingleOrDefault();
 
help me please
thanx in advance.
Posted 25-Jun-12 19:10pm
Comments
Aman4.net at 26-Jun-12 0:18am
   
Please do explain your requirements and problems/errors in question. Still here is a clue based on your question:
In string comparison with C#, we need to check that values have same character casing and no extra spaces etc.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

hi,
 
I LINQ no need to use loop it goes through all the records available in collection and check for the given where condition and returns the matching data.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

  var UserID = (from row in dtp.AsEnumerable()
 where row.Field<int>("UserID")==comboBox1.SelectedValue
select row.Field<int>("UserID")).FirstOrDefault();
</int></int>
 
Any error about AsEnumerable, just add this assembly:
C:\Windows\Microsoft.NET\Framework\v4.0.30319\System.Data.DataSetExtensions.dll
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

Hi,
No need to loop if you are using a LINQ
 
int SelectedID = int.Parse(Combobox.SelectedValue);
 
int UserID = 0;
try{
 
UserID = (from row in dtp.AsEnumerable() where row.Field<datatype>("UserID")== SelectedID select row.field<datatype>("UserID").FirstorDefault();</datatype></datatype>
 
Thanks
www.alacraft.com.au
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 484
1 Peter Leow 443
2 Sergey Alexandrovich Kryukov 288
3 Kornfeld Eliyahu Peter 270
4 Maciej Los 230


Advertise | Privacy | Mobile
Web01 | 2.8.150301.1 | Last Updated 28 Jun 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100