Question Customizing queries based on radio button selections

dave72

New member
Joined
Apr 30, 2009
Messages
4
Programming Experience
Beginner
Hello,

I am a new to programming, trying to learn vb.net, so I apologize if my questions are very elementary or my terminology is incorrect. I am trying to format a query to an Oracle table based on user-selected radio buttons on a Windows form (i.e. the query will return different elements from the table based on the radio buttons selected). The query results will be placed in a listbox on the form. My thought was to make a Property containing my query like so:

Public ReadOnly Property SQL()

Get
Return "SELECT * from table1"
End Get

End Property

and then I have a sub that feeds this SQL property (containing the query) into an OracleConnection.

My problem is that I don't know how to customize that query depending on what radio buttons are selected by the user. Is a Property the best way to go about this, or is there some other way that may be better?

ANY help will be greatly appreciated. Thanks for your time.
 
Some Code:
VB.NET:
Public Function genQuery() As String
      Dim query As New Stringbuilder()
      query.Append("SELECT * FROM table1 WHERE ")

      If RadioButton1.Checked Then query.Append("col1 = 'a' AND ")
      If RadioButton2.Checked Then query.Append("col2 = 'b' AND ")
      If RadioButton3.Checked Then query.Append("col3 = 'c' AND ")
      If RadioButton4.Checked Then query.Append("col4 = 'd' AND ")
      If RadioButton5.Checked Then query.Append("col5 = 'e' AND ")

      Dim fin As String = query.ToString()

      If fin.Endswith(" AND ") Then
            genQuery = fin.Substring(0, fin.length - 6)
      Else
            genQuery = fin.Substring(0, fin.length - 7)
      End If
End Function

Bobby
 
Back
Top