Results 1 to 5 of 5

Thread: Combo box & database query

Threaded View

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2003
    Posts
    8

    Combo box & database query

    I am using vb.net. In my homework, I need to have:
    1. a combo box with a list of predefined queries, with a button when clicked to retrieve data defined by that query
    2. A text box where user can put in his own query, add this query to the combo box list, and be able to retrieve data defined by user's query

    I got most part done, but there are some problems:
    1. when I run the predefined query, if it has keys linked to other tables, it shows those columns from other table in the data grid with null values for each field. How do I just make it show only the table columns, not the linked table columns?

    2. when I write a new query in the text box, and add it to the combo box list, it is not saved to the list, it is only good for that run session. If I close the app, and reopen it, the new query is not in the combo box list. How do save it to the combo list?

    Here is what I have so far:
    Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
    'clear dataset
    BooksDataSet1.Clear()
    End Sub

    Private Sub btnAddQuery_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAddQuery.Click
    'add new query to combo box list and clear the text box
    cboQuery.Items.Add(txtAddQuery.Text)
    txtAddQuery.Text = ""
    End Sub

    Private Sub btnQuery_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnQuery.Click
    BooksDataSet1.Clear()
    'run each predefined query
    Select Case cboQuery.SelectedIndex
    Case Is = 0
    BooksDataSet1.Clear()
    OleDbDataAdapter1.Fill(BooksDataSet1, "Authors")
    dgdResults.SetDataBinding(BooksDataSet1, "Authors")
    Case Is = 1
    BooksDataSet1.Clear()
    OleDbDataAdapter2.Fill(BooksDataSet1, "Publishers")
    dgdResults.SetDataBinding(BooksDataSet1, "Publishers")
    Case Is = 2
    BooksDataSet1.Clear()
    OleDbDataAdapter3.Fill(BooksDataSet1, "Authors")
    dgdResults.SetDataBinding(BooksDataSet1, "Authors")
    Case Is = 3
    BooksDataSet1.Clear()
    OleDbDataAdapter4.Fill(BooksDataSet1, "Publishers")
    dgdResults.SetDataBinding(BooksDataSet1, "Publishers")
    Case Else
    'run user defined query
    OleDbDataAdapter5.SelectCommand.CommandText = txtAddQuery.Text
    BooksDataSet1.Clear()
    OleDbDataAdapter5.Fill(BooksDataSet1, txtAddQuery.Text)
    dgdResults.SetDataBinding(BooksDataSet1, txtAddQuery.Text)
    End Select
    End Sub

    Thank you everyone! I have attached a picture of the form for question 1.
    Attached Images Attached Images  

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width