Using a combobox to query the database

后端 未结 2 1863
轮回少年
轮回少年 2021-01-29 08:23

I have all the days of the week in a combobox, yet when selecting a day all the days are shown in my data grid... How can I use the one selected value from the combobox to searc

2条回答
  •  独厮守ぢ
    2021-01-29 08:49

    You can Simply make a filter in your datagridview using following code

    Dim column As String = 'Your weekday column Name in Datagridview
    Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
    
        Dim rows = ds.Tables(0).Select("Convert(" & column & ", 'System.String') LIKE '*" + ComboBox1.SelectedItem + "*'")
    
        Try
            DGTimeTable.DataSource = rows.CopyToDataTable
        Catch ex As Exception
        End Try
    End Sub
    

提交回复
热议问题