Imports System.Data.OleDb
Public Class Form1
Dim con As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\SIR.accdb")
Dim sql As String = "SELECT * FROM [SIR]"
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Using da As New OleDbDataAdapter(sql, con)
Dim dt As New DataTable
da.Fill(dt)
Me.DGVSearch.DataSource = dt
End Using
End Sub
Private Sub btnSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSearch.Click
Using da As New OleDbDataAdapter(sql, con)
Dim w As New List(Of String)
'' البحث عن التاريخ
'If txtStartDate.Text <> "" Then
' sb.Append("[start] >= @start")
' da.SelectCommand.Parameters.AddWithValue("@start", txtStartDate.Text)
'End If
'' البحث عن التاريخ
'If txtEndDate.Text <> "" Then
' sb.Append("[end] <= @end")
' da.SelectCommand.Parameters.AddWithValue("@end", txtEndDate.Text)
'End If
If ComboBox1.Text <> "" Then
w.Add("[City] = @city")
da.SelectCommand.Parameters.AddWithValue("@city", ComboBox1.Text)
End If
If ComboBox2.Text <> "" Then
w.Add("[Region] = @region")
da.SelectCommand.Parameters.AddWithValue("@region", ComboBox2.Text)
End If
'If ComboBox3.Text <> "" Then
' w.Add("[Nod] = @nod")
' da.SelectCommand.Parameters.AddWithValue("@nod", ComboBox3.Text)
'End If
If ComboBox4.Text <> "" Then
w.Add("[FON] = @fon")
da.SelectCommand.Parameters.AddWithValue("@fon", ComboBox4.Text)
End If
If w.Count > 0 Then
da.SelectCommand.CommandText = sql & " WHERE " & String.Join(" AND ", w)
End If
Dim dt As New DataTable
da.Fill(dt)
Me.DGVSearch.DataSource = dt
End Using
End Sub
Private Sub btnReset_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnReset.Click
Using da As New OleDbDataAdapter(sql, con)
Dim dt As New DataTable
da.Fill(dt)
Me.DGVSearch.DataSource = dt
End Using
ComboBox1.Text = ("")
ComboBox2.Text = ("")
ComboBox3.Text = ("")
ComboBox4.Text = ("")
End Sub
End Class