I'm trying to build a function on a single button, to search my database based on the selections that are made in multiple comboboxes. I have four comboboxes that can be null or valued. My final result should be to be able to filter the datagridview by enhancing the comboboxes and thus obtain dynamic and concatenated queries.
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