trying to pass parameter along...

chrisatpsu

Member
Joined
Feb 26, 2012
Messages
7
Programming Experience
3-5
I have a query like this...

SELECT DISTINCT Bible, BookTitle
FROM Bible
WHERE (Bible = BibleSelection)
ORDER BY BookTitle

on form, i have code like this...

Dim BibleSelection As String
BibleSelection = cmbBibles.Text
Me.BibleTableAdapter1.Fill(Me.QueryBookTitle.Bible)

I need to know how to write this...

Me.BibleTableAdapter1.Fill(Me.QueryBookTitle.Bible)

to pass along BibleSelection as a parameter.

the general idea is I have a query filling DISTINCT values in a combobox (cmbBibles)
I want to have the next combobox (cmbBooks) fill it's values based from what was selected in cmbBibles

Visual Basic 2010
 
Following this... How to: Fill a Dataset with Data

i tried to write it as
Me.BibleTableAdapter1.FillByBibleSelection(Me.QueryBookTitle.Bible, 'BibleSelection')
but the IDE gives me...
Error 1 'FillByBibleSelection' is not a member of 'ChurchPresenter.QueryBookTitleTableAdapters.BibleTableAdapter'. E:\ChurchPresenter\ChurchPresenter\BibleVerseLookup.vb 10 9 ChurchPresenter
 
That FillByBibleSelection method doesn't exist by default. You have to add it. You do that in the DataSet designer. You should do some reading specifically on TableAdapters:

TableAdapters

You'll notice that one of the links is specifically on creating queries.
 
ok, so i modify my query to... (using OleDbProvider)

SELECT DISTINCT Bible, BookTitle
FROM Bible
WHERE (Bible = ?)
ORDER BY BookTitle

if I have multiple queries, then i just need to make sure i attach them to the statement in order?
 
if I have multiple queries, then i just need to make sure i attach them to the statement in order?
Do you actually mean multiple criteria in the one query?
 
ok, changed to... and it works!
(have to get used to posting code on here, it jumbles it together)

Private Sub cmbBibles_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbBibles.SelectedIndexChanged

BibleSelection = cmbBibles.Text
Me.BibleTableAdapter1.FillByBible(Me.QueryBookTitle.Bible, BibleSelection)

End Sub
 
Do you actually mean multiple criteria in the one query?

Yeah, I did this, and it works. I hope I'm coding this the way it should be. I'm always open to suggestion. If I'm going to learn this, I might as well do it right.

Private Sub cmbBooks_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbBooks.SelectedIndexChanged

BookSelection = cmbBooks.Text
Me.BibleTableAdapter2.Fill(Me.QueryChapter.Bible, BibleSelection, BookSelection)
End Sub
 
If you want to post VB code then use [xcode=vb]your code here[/xcode] and if you want to post any other language then use [code]your code here[/code]. There are buttons for both on the advanced editor.

Generally speaking, you should not change the default query of a TableAdapter. Leave it as retrieving all the data and, if you want to be able to filter, just add one or more queries as required. For instance, if you have a Person table with PersonID, GivenName and FamilyName columns then you would start with the default query:
VB.NET:
SELECT *
FROM Person
which would be invoked by the Fill and GetData methods. You might then add a query like so:
VB.NET:
SELECT *
FROM Person
WHERE PersonID = ?
and that would be invoked by the FillByPersonID and GetDataByPersonID methods. You might also add a query like so:
VB.NET:
SELECT *
FROM Person
WHERE GivenName = ?
AND FamilyName = ?
and that would be invoked by the FillByGivenNameAndFamiliyName and GetDataByGivenNameAndFamiliyName methods. The default query would require no additional arguments, the second query would require a PersonID value to be passed as an argument and the last query would require a GivenName and a FamilyName value to be passed as arguments.
 
Back
Top