Click here to Skip to main content
15,891,708 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
SQL
select ID,AmountFrom,AmountTo,DiscountPercent
frOM Discount where  2000 between AmountFrom and AmountTo
order by DiscountPercent desc



့how to write with linq above statament to retrive from data table

pls help me!!!!!!!
Posted
Updated 14-Jun-12 6:05am
v2
Comments
Ganesan Senthilvel 14-Jun-12 12:06pm    
SQL query format

I would try:

VB
dim q = (from d in Discount
         where (d.AmountFrom >= 2000 andalso d.AmountTo <= 2000)
         order by d.DiscountPercent descending
         Select d.ID, d.AmountFrom, d.AmountTo, d.DiscountPercent).ToList()


or (db being the context)

VB
dim q = from db.Discount.Where(function(d) (d.AmountFrom >= 2000 andalso d.AmountTo <= 2000))


ref: http://stackoverflow.com/questions/1414893/linq-to-sql-value-between-two-double-values[^]

Oh, yeah can I really recommend a tool that will help massivly with Linq stuff!!!

LinqPad!!!!
http://www.linqpad.net/[^]
 
Share this answer
 
v3
If you have a DataTable with that data in it already, this VB.NET code should work:

VB
Dim myData = From d In myDataTable.AsEnumerable() _
             Where d.AmountFrom > 2000 AndAlso d.AmountTo < 2000
             Select d _
             Order By d.DiscountPercent Descending


Note that you have to use the AsEnumerable extension method, which is included in the System.Data.DataSetExtensions class. You can find out more about this here:

http://stackoverflow.com/questions/10855/linq-query-on-a-datatable[^]

If you want to use Linq2Sql directly (which I would recommend instead of using ADO.NET to get a DataTable, this article will give you all the help you need:

Using LINQ to SQL in Visual Basic[^]

Also note that the Where clause is a bit sticky. I wasn't sure what you wanted to do exactly so I got it close. You can further modify it as you need.
 
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