-1
我有一整天的組合框,但是當選擇一天時,所有的日子都顯示在我的數據網格中......我如何使用組合框中的一個選定值只搜索該值。使用組合框查詢數據庫
Private Sub btnViewTimeTable_Click(sender As Object, e As EventArgs) Handles btnViewTimeTable.Click
If (cbDay.Text = "Monday" Or cbDay.Text = "Tuesday" Or cbDay.Text = "Wednesday" Or cbDay.Text = "Thursday" Or cbDay.Text = "Friday" Or cbDay.Text = "Saturday" Or cbDay.Text = "Sunday") Then
Dim SqlQuery As String = "SELECT Time, Activity, Equipment FROM TimeTable WHERE Day = cbDay"
Dim da As OleDbDataAdapter = New OleDbDataAdapter(SqlQuery, conn)
Dim ds As DataSet = New DataSet
da.Fill(ds, "Table")
Dim dt As DataTable = ds.Tables("Table")
With DGTimeTable
.AutoGenerateColumns = True
.DataSource = ds
.DataMember = "Table"
End With
With DGTimeTable
.Columns(0).Width = 108
.Columns(1).Width = 154
.Columns(2).Width = 278
Me.DGTimeTable.DefaultCellStyle.WrapMode = DataGridViewTriState.True
Me.DGTimeTable.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells
End With
Else
MsgBox("Please Select a Day!")
End If
End Sub