Imports System.Data
Imports System.Data.OleDb
Public Class FormHistory
Private _dataset As DataSet
Private _conn As OleDbConnection
Private _cmd As OleDbCommand
Private _adapter As OleDbDataAdapter
Private Sub FormHistory_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
_conn = New OleDbConnection(_conStr)
_conn.Open()
Dim sql As String = "SELECT * FROM Customers"
_cmd = New OleDbCommand(sql, _conn)
Dim reader As OleDbDataReader = _cmd.ExecuteReader()
While reader.Read()
CmbCust.Items.Add(reader("CustomerName"))
End While
sql = "SELECT * FROM Orders"
_cmd = New OleDbCommand(sql, _conn)
reader = _cmd.ExecuteReader()
While reader.Read
Cmbmonth.Items.Add(reader("OrderedDate"))
End While
CmbCust.SelectedIndex = 0
Cmbmonth.SelectedIndex = 0
End Sub
Private Sub ShowOrders()
Dim sql As String
sql = "SELECT * FROM Orders WHERE CustomerName = @cust"
_cmd = New OleDbCommand(sql, _conn)
_cmd.Parameters.AddWithValue("cust", CmbCust.SelectedItem)
sql = "SELECT * FROM Orders WHERE OrderedDate = @orde"
_cmd = New OleDbCommand(sql, _conn)
_cmd.Parameters.AddWithValue("orde", Cmbmonth.SelectedItem)
_adapter = New OleDbDataAdapter(_cmd)
_dataset = New DataSet()
_adapter.Fill(_dataset, "ord")
End sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
ShowOrders()
End Sub