我正在尝试在单个按钮上构建一个功能,以根据在多个组合框中进行的选择来搜索我的数据库。我有四个组合框,可以为空或有值。我的最终结果应该是能够通过增强组合框来过滤数据网格视图,从而获得动态和连接的查询。
Private Sub Button10_Click_1(sender As Object, e As EventArgs) Handles Button10.Click
Dim conn As New
FbConnection("User=SYSDBA;Password=masterkey;Database=..\DB.gdb;DataSource=localhost;Port=3050;Dialect=3;Charset=NONE;Role=;Connection lifetime=15;Pooling=true;MinPoolSize=0;MaxPoolSize=50;Packet Size=8192;ServerType=0;")
Dim startdate As String = DateTimePicker1.Value.ToString("dd.MM.yyyy")
Dim enddate As String = Microsoft.VisualBasic.DateAdd(DateInterval.Day, 1, DateTimePicker2.Value).ToString("dd.MM.yyyy")
Dim adapter As New FbDataAdapter("SELECT * from ORDER WHERE DATEORDER BETWEEN @StartDate AND @EndDate AND ZIPCODE = CASE WHEN @Param1 IS NULL THEN ZIPCODE ELSE @Param1 END ", conn)
adapter.SelectCommand.Parameters.AddWithValue("@Param1", ComboBox5.Text)
adapter.SelectCommand.Parameters.AddWithValue("@Param2", ComboBox3.Text)
Dim table As New DataTable
adapter.Fill(table)
DataGridView1.DataSource = table
End Sub