Question : Passing parameters via code on queries created using TableAdapter Query Wizard

hi all,

I have a vb.net program that displays data from my ms Access 2007 database using a DataGridView. To sort out the data to be displayed, I created a few query strings using the TableAdapter Query Configuration Wizard. And my program will flow in this way:

A user will select from a combox a particular item by which he/she would like to sort out the data. Based on the user's selection, i will call upon my preset query by using the FillBy command and the data displayed on my DataGridView will follow suite.

Vb program details:
  - uses ms Access 2007 as database
  - is edited locally (including the database - program will only display data, not allow users to update) but is published and run from a website and is available only online (vb publish options)
  - published data will include the database (which is then deployed as MyDB.mdb.deploy)

Part of my code that displays data based on my preset query is as follows:

Private Sub cmbSort_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbSort.SelectedIndexChanged

            Select Case cmbSort.Text
                Case "Metal"
                    Me._103TableAdapter.FillBy_103_Metal(Me.ElectricalDataSet._103)
                Case "UPVC"
                    Me._103TableAdapter.FillBy_103_UPVC(Me.ElectricalDataSet._103)
                Case "All"
                    Me._103TableAdapter.Fill(Me.ElectricalDataSet._103)
            End Select

As by creating query strings using the Wizard, the queries are on my table adapter as shown on the attached image.

My question is, is there a way for me to edit a query or pass a parameter to a query created using the Wizard via code? This would eliminate the need for me to create several queries beforehand, and instead use one query whose parameters i edit via code on runtime. Thank you all in advance!

Answer : Passing parameters via code on queries created using TableAdapter Query Wizard

hi codecruiser, thank you for the input. i am sorry for the late response, i had been sick for the past few days. i have had a day to try out your solution, but have failed to produce a desired result especially when i deploy my program to a server.

in a bid to follow through with my original question, i have tried the properties associated with the table adapter for me to access the command text. and fortunately, i have found a solution. Instead of using TableName.SelectCommand right away, it would be TableName.Adapater.SelectCommand.CommandText.

In reference to my example for my original question, i was able to edit the query via code using the following command:

    _140TableAdapter.Adapter.SelectCommand.CommandText = "Select * From ...."

In any case, I thank you for your willingness to help.
Random Solutions  
 
programming4us programming4us