Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone



Clound SSD Virtual Server

WHERE BETWEEN (LINQ, Entity Framework)

WHERE LIKE / NOT LIKE (LINQ, Entity Framework) บน LINQ to Entities จะไม่มีคำสั่ง BETWEEN เหมือนกับ SQL Statement ฉะนั้น การที่จะเขียน BETWEEN บน LINQ จะต้องใช้การเปรียบเทียบช่วง Period ระหว่าง 2 ข้อความ ด้วย >= และ <= แต่ในบน String จะต้องใช้การ ComareTo ก่อนที่จะใช้ ส่วนบนค่าที่เป็น Integer และ DateTime สามารถใช้ได้เลย

String BETWEEN (ข้อความ)
string strFrom = "A";
string strTo = "D";
where c.NAME.CompareTo(strFrom) >= 0 && c.NAME.CompareTo(strTo) <= 0
Number BETWEEN (ตัวเลข)
int iFrom = 100000;
int iTo = 700000;
where c.USED >= iFrom && c.USED <= iTo
DateTime BETWEEN (วันที่)
DateTime dtFrom = Convert.ToDateTime("10-Aug-2015");
DateTime dtTo = Convert.ToDateTime("25-Aug-2015");
where c.LOG_DATE >= dtFrom && c.LOG_DATE <= dtTo


Example 1 : การใช้ LINQ ในการ BETWEEN ด้วย String (ข้อความ)

Code (C#)
         private void frmMain_Load(object sender, EventArgs e)
        {
            // Create new entities Object
            using (var db = new myDatabaseEntities())
            {
                //Between string
                string strFrom = "A";
                string strTo = "D";

                // Get data from CUSTOMER
                var ds = (from c in db.CUSTOMER
                          where c.NAME.CompareTo(strFrom) >= 0 && c.NAME.CompareTo(strTo) <= 0
                          select c).ToList();

                // if found item rows
                if (ds.Count() > 0)
                {
                    this.myDataGridView.DataSource = ds;
                }
            }
        }
Code (VB.Net)
    Private Sub frmMain_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        ' Create new entities Object
        Using db = New myDatabaseEntities()
            'Between string
            Dim strFrom As String = "A"
            Dim strTo As String = "D"

            ' Get data from CUSTOMER
            Dim ds = (From c In db.CUSTOMER
                      Where c.NAME.CompareTo(strFrom) >= 0 And c.NAME.CompareTo(strTo) <= 0
                      Select c).ToList()

            ' if found item rows
            If ds.Count() > 0 Then
                Me.myDataGridView.DataSource = ds
            End If
        End Using
    End Sub

Screenshot

WHERE BETWEEN (LINQ, Entity Framework)








Example 2 : การใช้ LINQ ในการ BETWEEN ด้วย Number (ตัวเลข)

Code (C#)
        private void frmMain_Load(object sender, EventArgs e)
        {
            // Create new entities Object
            using (var db = new myDatabaseEntities())
            {
                //Between Number or Integer
                int iFrom = 100000;
                int iTo = 700000;

                // Get data from CUSTOMER
                var ds = (from c in db.CUSTOMER
                          where c.USED >= iFrom && c.USED <= iTo
                          select c).ToList();

                // if found item rows
                if (ds.Count() > 0)
                {
                    this.myDataGridView.DataSource = ds;
                }
            }
        }
Code (VB.Net)
    Private Sub frmMain_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        ' Create new entities Object
        Using db = New myDatabaseEntities()
            'Between Number or Integer
            Dim iFrom As Integer = 100000
            Dim iTo As Integer = 700000

            ' Get data from CUSTOMER
            Dim ds = (From c In db.CUSTOMER
                      Where c.USED >= iFrom And c.USED <= iTo
                      Select c).ToList()

            ' if found item rows
            If ds.Count() > 0 Then
                Me.myDataGridView.DataSource = ds
            End If
        End Using
    End Sub

Screenshot

WHERE BETWEEN (LINQ, Entity Framework)

Example 2 : การใช้ LINQ ในการ BETWEEN ด้วย DateTime (วันที่)

Code (C#)
        private void frmMain_Load(object sender, EventArgs e)
        {
            // Create new entities Object
            using (var db = new myDatabaseEntities())
            {
                //Between DateTime
                DateTime dtFrom = Convert.ToDateTime("10-Aug-2015");
                DateTime dtTo = Convert.ToDateTime("25-Aug-2015");

                // Get data from AUDIT
                var ds = (from c in db.AUDIT
                          where c.LOG_DATE >= dtFrom && c.LOG_DATE <= dtTo
                          select c).ToList();

                // if found item rows
                if (ds.Count() > 0)
                {
                    this.myDataGridView.DataSource = ds;
                }
            }
        }
Code (VB.Net)
    Private Sub frmMain_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        ' Create new entities Object
        Using db = New myDatabaseEntities()
            'Between DateTime
            Dim dtFrom As DateTime = Convert.ToDateTime("10-Aug-2015")
            Dim dtTo As DateTime = Convert.ToDateTime("25-Aug-2015")

            ' Get data from AUDIT
            Dim ds = (From c In db.AUDIT
                      Where c.LOG_DATE >= dtFrom And c.LOG_DATE <= dtTo
                      Select c).ToList()

            ' if found item rows
            If ds.Count() > 0 Then
                Me.myDataGridView.DataSource = ds
            End If
        End Using
    End Sub

Screenshot

WHERE BETWEEN (LINQ, Entity Framework)







.

   
Share


ช่วยกันสนับสนุนรักษาเว็บไซต์ความรู้แห่งนี้ไว้ด้วยการสนับสนุน Source Code 2.0 ของทีมงานไทยครีเอท


ลองใช้ค้นหาข้อมูล


   


Bookmark.   
       
  By : ThaiCreate.Com Team (บทความเป็นลิขสิทธิ์ของเว็บไทยครีเอทห้ามนำเผยแพร่ ณ เว็บไซต์อื่น ๆ)
  Score Rating :  
  Create/Update Date : 2015-10-02 21:16:03 / 2017-03-24 23:05:27
  Download : No files
 Sponsored Links / Related

 
รู้จัก Entity Framework (EF) คืออะไร ใช้ทำอะไร และมีประโยชน์อย่างไรบน .Net Framework
Rating :

 
สร้าง Entity Framework เพื่อติดต่อกับ Database การสร้าง Model Entities บน Visual Studio
Rating :

 
List(T) คืออะไร Generic Class ของ List ใช้งานกับ Entity Framework และ LINQ to Entities
Rating :

 
เรียกใช้งาน Entity Framework การ Select ข้อมูลจาก Entities แสดงผลบน DataSource Control
Rating :

 
Loop and Get Data (LINQ, Entity Framework)
Rating :

 
WHERE Clause (LINQ, Entity Framework)
Rating :

 
Entity & Relation (Foreign Key , CasCade , Delete , Update) (LINQ, Entity Framework)
Rating :

 
WHERE IN / NOT IN (LINQ, Entity Framework)
Rating :

 
WHERE LIKE / NOT LIKE (LINQ, Entity Framework)
Rating :

 
ORDER BY and Sorting Data (ASC, DESC) (LINQ, Entity Framework)
Rating :

 
Compare DateTime (LINQ, Entity Framework)
Rating :

 
Join Clause (LINQ, Entity Framework)
Rating :

 
Left Join (LINQ, Entity Framework)
Rating :

 
Right Join (LINQ, Entity Framework)
Rating :

 
Union (LINQ, Entity Framework)
Rating :

 
VIEW Table (LINQ, Entity Framework)
Rating :

 
Add Entity : Insert Rows Into Database (LINQ, Entity Framework)
Rating :

 
Update Entity : Update Rows in Database (LINQ, Entity Framework)
Rating :

 
Delete Entity : Delete Rows in Database (LINQ, Entity Framework)
Rating :

 
Entity Framework and Try Catch Exception (LINQ, Entity Framework)
Rating :

 
Entity Framework and Transaction Scope (LINQ, Entity Framework)
Rating :

 
Get Connection String & Connection State (LINQ, Entity Framework)
Rating :

 
Select Entity to List<Object> (LINQ, Entity Framework)
Rating :

 
Entity Execute SQL Query : INSERT/UPDATE/DELETE (LINQ, Entity Framework)
Rating :

 
Entity Select SQL (Statement) Query (LINQ, Entity Framework)
Rating :

 
Entity and Stored Procedure (LINQ, Entity Framework)
Rating :

 
เทคนิคการใช้ IntelliTrace ในการ Debug ตรวจสอบ Performance ของโปรแกรม
Rating :

 
Windows Form ตอนที่ 1 : DataGridView List Show Data (LINQ, Entity Framework)
Rating :

 
Windows Form ตอนที่ 2 : DataGridView Search Data (LINQ, Entity Framework)
Rating :

 
Windows Form ตอนที่ 3 : DataGridView Display Master-Detail (LINQ, Entity Framework)
Rating :

 
Windows Form ตอนที่ 4 : Add Data (LINQ, Entity Framework)
Rating :

 
Windows Form ตอนที่ 5 : Update Data (LINQ, Entity Framework)
Rating :

 
Windows Form ตอนที่ 6 : Delete Data (LINQ, Entity Framework)
Rating :

 
ASP.Net ตอนที่ 1 : GridView List Show Data (LINQ, Entity Framework)
Rating :

 
ASP.Net ตอนที่ 2 : GridView Search Data (LINQ, Entity Framework)
Rating :

 
ASP.Net ตอนที่ 3 : Display Master-Detail (LINQ, Entity Framework)
Rating :

 
ASP.Net ตอนที่ 4 : Add Data (LINQ, Entity Framework)
Rating :

 
ASP.Net ตอนที่ 5 : Update Data (LINQ, Entity Framework)
Rating :

 
ASP.Net ตอนที่ 6 : Delete Data (LINQ, Entity Framework)
Rating :

 
การใช้งาน Entity Framework กับ MySQL Database (LINQ to Entities - MySQL Database)
Rating :

 
การใช้งาน Entity Framework กับ Oracle Database (LINQ to Entities - Oracle Database)
Rating :


ThaiCreate.Com Forum


Comunity Forum Free Web Script
Jobs Freelance Free Uploads
Free Web Hosting Free Tools

สอน PHP ผ่าน Youtube ฟรี
สอน Android การเขียนโปรแกรม Android
สอน Windows Phone การเขียนโปรแกรม Windows Phone 7 และ 8
สอน iOS การเขียนโปรแกรม iPhone, iPad
สอน Java การเขียนโปรแกรม ภาษา Java
สอน Java GUI การเขียนโปรแกรม ภาษา Java GUI
สอน JSP การเขียนโปรแกรม ภาษา Java
สอน jQuery การเขียนโปรแกรม ภาษา jQuery
สอน .Net การเขียนโปรแกรม ภาษา .Net
Free Tutorial
สอน Google Maps Api
สอน Windows Service
สอน Entity Framework
สอน Android
สอน Java เขียน Java
Java GUI Swing
สอน JSP (Web App)
iOS (iPhone,iPad)
Windows Phone
Windows Azure
Windows Store
Laravel Framework
Yii PHP Framework
สอน jQuery
สอน jQuery กับ Ajax
สอน PHP OOP (Vdo)
Ajax Tutorials
SQL Tutorials
สอน SQL (Part 2)
JavaScript Tutorial
Javascript Tips
VBScript Tutorial
VBScript Validation
Microsoft Access
MySQL Tutorials
-- Stored Procedure
MariaDB Database
SQL Server Tutorial
SQL Server 2005
SQL Server 2008
SQL Server 2012
-- Stored Procedure
Oracle Database
-- Stored Procedure
SVN (Subversion)
แนวทางการทำ SEO
ปรับแต่งเว็บให้โหลดเร็ว


Hit Link
   







Load balance : Server 01
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่