ปัญหาที่หลายคนต้องปวดหัวกับการที่ต้องเขียนโค้ดดึงข้อมูลที่มีหลายๆเงื่อนไข แล้วจะต้องดึงข้อมูลหลายๆครั้งตามเงื่อนไขที่เราเลือกตัวอย่าง การดึงข้อมูลบุคคลตามรูปครับ
เมื่อกดปุ่มค้นหา เราสามารถใช้ Partial Class เพื่อดึงข้อมูลแบบใช้เงื่อนไขได้หลายๆแบบใน Dataset ดังนี้
1. เริ่มจากการสร้าง Dataset และ TableAdapter ขึ้นมาเป็นโครงก่อน แล้วค่อยทำ Partial อีกที
	
จากรูป คำสั่ง Sql query คือ select * from personel  แค่นี้นะครับ  ก็จะได้ TableAdapter ที่เป็นโครงแต่ยังไม่ได้ระบุเงื่อนไขแล้ว
2. ทีนี้เราก็มาสร้าง Partial Class ขึ้นมาเพื่อใส่เงื่อนไขลงไปในการคิวรี่ข้อมูล โดยการสร้างคลาสดังนี้
	Option Strict Off
	Option Explicit On
	Imports Microsoft.VisualBasic
	Imports System
	Namespace Person_SearchDataSetTableAdapters
	    Partial Public Class personelTableAdapter
	        Inherits System.ComponentModel.Component
	        Public Function GetData2(ByVal dataTable As Person_SearchDataSet.personelDataTable, ByVal SQLExpression As String) As Integer
	            Dim OriginalCommandText As String
	            OriginalCommandText = Me.CommandCollection(0).CommandText
	            Try
	                Me.CommandCollection(0).CommandText += SQLExpression
	                Return Me.Fill(dataTable)
	            Catch ex As Exception
	            Finally
	                Me.CommandCollection(0).CommandText = OriginalCommandText
	            End Try
	        End Function
	    End Class
	End Namespace
*เป็นการสร้างฟังก์ชัน SearchPersonel ขึ้นมาโดยส่ง DataTable และ Sql Expression มาต่อจากของเดิม (ดูได้จากบรรทัดที่ 14 >> Me.CommandCollection(0).CommandText += SQLExpression ) ถ้าอยากเขียน Sql ใหม่ทั้งหมดมา query ก็ให้เอา + ออก
	3. เรียกใช้งาน  GetData2 โดยสร้าง Sql ตามเงื่อนไข ดังนี้
	
Protected Sub BtnOK_Click(sender As Object, e As EventArgs) Handles BtnOK.Click
	        Dim sql As String = " where 1=1 "
	        If Combo_rank.SelectedValue > 0 Then  ' ถ้ามีการเลือกคำนำหน้า/ยศ
	            sql += " and rnk_id = " & Combo_rank.SelectedValue
	        End If
	        If Val(Combo_person_full_name.SelectedValue) > 0 Then  ' ถ้ามีการเลือกชื่อ-นามสกุล
	            sql += " and per_id = " & Combo_person_full_name.SelectedValue
	        End If
	        If Val(Combo_person_stat.SelectedValue) > 0 Then  'ถ้ามีการเลือกสถานะ
	            sql += " and per_status = " & Combo_person_stat.SelectedValue
	        End If
	        If Val(Radio_gender.SelectedValue) > 0 Then  'ถ้ามีการเลือกเพศ
	            sql += " and per_gender = " & Radio_gender.SelectedValue
	        End If
	        If Val(Combo_unit_name.SelectedValue) > 0 Then  ' ถ้ามีการเลือกหน่วยงาน
	            sql += " and unt_id = " & Combo_unit_name.SelectedValue
	        End If
	        If Val(Combo_person_type.SelectedValue) > 0 Then  ' ถ้ามีการเลือกประเภทบุคลากร
	            sql += " and person_type = " & Combo_person_type.SelectedValue
	        End If
	        Dim personAdapter As New Person_SearchDataSetTableAdapters.personelTableAdapter
	        Dim dataPerson As New Person_SearchDataSet.personelDataTable
	        personAdapter.GetData2(dataPerson, sql)   ' เรียกใช้งาน Partial Class
	        RadGrid1.DataSource = dataPerson
	        RadGrid1.DataBind()
End Sub
* เมื่อเรียกใช้งาน GetData2 ซึ่งเป็น Partial Class ที่เราได้สร้างไว้ ก็จะได้ข้อมูลออกมาตามเงื่อนไขที่เราส่งเข้าไปในฟังก์ชัน ผ่าน Sql Expression นั่นเอง



