Click here to Skip to main content
15,891,529 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
I try it by using datatable like that

C#
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

SQL
int ID = (from s in con.TUsers
                                    where s.UserId.Equals(comboBox1.SelectedValue)
                                    select s.UserId).SingleOrDefault();


help me please
thanx in advance.
Posted
Comments
Aman4.net 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.

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.
 
Share this answer
 
C#
  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
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900