Hi everyone,
I am relatively new to VB.Net, and database programming.
I have a database with four tables, set up as follows:
tblBook
BookID... key
Book... All the book titles of the Bible
tblChapter
ChapterID... key
Chapter... chapter numbers (1 - 150)
tblVerse
VerseID... key
Verse... verse number (1 - 100)
tblVerseText
ID... key
BookID
ChapterID
VerseID
VerseText... Each verse from the Bible, each in its own record
In VB.Net, I have a form with three ComboBoxes and one Label:
cmbBook... to display all the Book titles
cmbChapter... to display all the Chapter numbers
cmbVerse... to display all the verse numbers
lblVerseText... to display the verse corresponding to the selections made in
the three ComboBoxes
I can get each ComboBox to display the information from the corresponding
tables, however, I want to be able to filter each subsequent ComboBox, and
the label, to display only the information that is common to the preceding
selection.
For example:
You select 'Genesis' in cmbBook, and cmbChapter will only display the
numbers 1 - 22, (the number of chapters in Genesis).
Then you select '1' in cmbChapter, and cmbVerse will only display the
numbers 1 - 31, (the number of verses in Genesis-1).
Then you select '1' in cmbVerse, and lblVerseText will only display the
verse Genesis,1,1.
As I stated earlier, I can get each ComboBox to display ALL of the
corresponding data from their respective tables, but I would like to filter
the data according to the data currently selected in any of the COmboBoxes.
Any help would be gretly appreciated,
Gary 15 1522
One way . . .
For each dataTable, set up a DataView. In the selectedIndexCh anged event
change the filter parameters of cascading combo boxes to correspond with the
key found in the relation above. Bind the comboboxes to the DataView not the
table, except the master table.
Another way,
Is to set up relations for each table relation, and set up the binding so
the secondary boxes get the data from the relation. Ive done this with grids
but not with combo boxes but it should work.
OHM
Bo Diddly wrote: Hi everyone,
I am relatively new to VB.Net, and database programming. I have a database with four tables, set up as follows:
tblBook BookID... key Book... All the book titles of the Bible tblChapter ChapterID... key Chapter... chapter numbers (1 - 150) tblVerse VerseID... key Verse... verse number (1 - 100) tblVerseText ID... key BookID ChapterID VerseID VerseText... Each verse from the Bible, each in its own record
In VB.Net, I have a form with three ComboBoxes and one Label:
cmbBook... to display all the Book titles cmbChapter... to display all the Chapter numbers cmbVerse... to display all the verse numbers lblVerseText... to display the verse corresponding to the selections made in the three ComboBoxes
I can get each ComboBox to display the information from the corresponding tables, however, I want to be able to filter each subsequent ComboBox, and the label, to display only the information that is common to the preceding selection.
For example:
You select 'Genesis' in cmbBook, and cmbChapter will only display the numbers 1 - 22, (the number of chapters in Genesis). Then you select '1' in cmbChapter, and cmbVerse will only display the numbers 1 - 31, (the number of verses in Genesis-1). Then you select '1' in cmbVerse, and lblVerseText will only display the verse Genesis,1,1.
As I stated earlier, I can get each ComboBox to display ALL of the corresponding data from their respective tables, but I would like to filter the data according to the data currently selected in any of the COmboBoxes.
Any help would be gretly appreciated,
Gary
Regards - OHM# OneHandedMan{at }BTInternet{dot }com
Hi Bo Diddy,
In addition to OHM about the comboboxes,
have a look at datasource, datamembers, and value members from the combobox,
using that it is not that difficult I thought,
Cor
Thank you to OHM and Cor,
I will try it out as soon as I get a chance, maybe before tomorrow
(Saturday), and I will let you know.'
Gary
This is what I've done so far:
I have a DataBase with:
tblBook
BookID... key
Book... All the book titles of the Bible
tblChapter
ChapterID... key
Chapter... chapter numbers (1 - 150)
tblVerse
VerseID... key
Verse... verse number (1 - 100)
tblVerseText
ID... key
BookID
ChapterID
VerseID
VerseText... Each verse from the Bible, each in its own record
Created a DataAdapter for each table, (when I run the SQL statements within the configuration wizard, they do what I want them to do):
daBook... SELECT Book,BookID FROM tblBook ORDER BY BookID
daChapter... SELECT DISTINCT tblChapter.Chap ter, tblChapter.Chap terID, tblVerseText.Ch apterID AS Expr1, tblVerseText.Bo okID FROM tblChapter INNER JOIN tblVerseText ON tblChapter.Chap terID = tblVerseText.Ch apterID WHERE (tblVerseText.B ookID = ?) ORDER BY tblChapter.Chap terID
daVerse... SELECT DISTINCT tblVerse.Verse, tblVerse.VerseI D, tblVerseText.Ch apterID, tblVerseText.Ve rseID AS Expr1 FROM tblVerse INNER JOIN tblVerseText ON tblVerse.VerseI D = tblVerseText.Ve rseID WHERE (tblVerseText.C hapterID = ?) ORDER BY tblVerse.VerseI D
daText... SELECT VerseText, ID, VerseID FROM tblVerseText WHERE (VerseID = ?) ORDER BY ID
Created a DataView for each DataSet
dvBook
dvChapter
dvVerse
dvText
The Controls on the form are bound to the DataViews:
cmbBook > dvBook
cmbChapter > dvChapter
cmbVerse > dvVerse
lblText > dvText
I need the item that is selected in each ComboBox to filter the choices in the subsequent ComboBoxes.
How do I write the statement in the SelectedItemCha nged event to take the value displayed and pass it's corresponding key to filter the next ComboBox?
Thanks in advance,
Gary
Cor and OHM,
Thanks for the push in the right direction.
I have been able to get the first ComboBox to work properly, (it wasn't a
problem though). I can retrieve the .value from the first ComboBox and pass
it into the SelectCommand for the second ComboBox. However, this is where I
am having problems now. My SelectCommand statement for the third ComboBox
works fine when I run it in the Query Builder or when I run Preview Data.
But when I run the program, it doesn't work properly.
-----------------------------------------
SELECT DISTINCT tblVerse.Verse, tblVerse.VerseI D, tblVerseText.Ve rseID AS
VerseKey, tblVerseText.Ch apterID AS ChapterKey, tblVerseText.Bo okID AS
BookKey
FROM tblVerse INNER JOIN tblVerseText ON
tblVerse.VerseI D = tblVerseText.Ve rseID
WHERE (tblVerseText.C hapterID = ?) AND (tblVerseText.B ookID = ?)
ORDER BY tblVerse.VerseI D
-----------------------------------------
-----------------------------------------
Private Sub cmbChapter_Sele ctedIndexChange d(ByVal sender As System.Object,
ByVal e As System.EventArg s) Handles cmbChapter.Sele ctedIndexChange d
daVerse.SelectC ommand.Paramete rs("ChapterID") .Value =
cmbChapter.Sele ctedValue
daVerse.SelectC ommand.Paramete rs("BookID").Va lue = cmbBook.Selecte dValue
dsVerse.Clear()
daVerse.Fill(ds Verse)
End Sub
-----------------------------------------
Can I somehow combine the first two lines in the cmbChapter_Sele ctedIndex
Changed event?
I am a little confused as to why the SQL statement works perfectly in the
Query Builder or Preview Data, but does not filter properly when the program
is run.
As I said , the first two ComboBoxes filter and display perfectly, but the
third ComboBox does not filter.
Thanks again for any nudges in the right direction,
Gary
Cor and OHM,
Thanks for the push in the right direction... everything is working fine
except...
The third ComboBox does not filter correctly. The SQL statement works
perfectly in the Query Builder or in Data Preview. But I cannot get the
ComboBox to filter correctly.
-------------------------------------
SELECT DISTINCT
tblVerse.Verse, tblVerse.VerseI D, tblVerseText.Ve rseID
AS VerseKey, tblVerseText.Ch apterID AS ChapterKey, tblVerseText.Bo okID AS
BookKey
FROM tblVerse INNER JOIN
tblVerseText ON tblVerse.VerseI D =
tblVerseText.Ve rseID
WHERE (tblVerseText.C hapterID = ?) AND (tblVerseText.B ookID = ?)
ORDER BY tblVerse.VerseI D
-------------------------------------
Private Sub cmbChapter_Sele ctedIndexChange d(ByVal sender As System.Object,
ByVal e As System.EventArg s) Handles cmbChapter.Sele ctedIndexChange d
daVerse.SelectC ommand.Paramete rs("ChapterID") .Value =
cmbChapter.Sele ctedValue
daVerse.SelectC ommand.Paramete rs("BookID").Va lue = cmbBook.Selecte dValue
dsVerse.Clear()
daVerse.Fill(ds Verse)
End Sub
-------------------------------------
In the code above, am I retrieving the two variables correctly to pass them
to the daVerse.SelectC ommand.Paramete rs? I know it is correct if only one
parameter is needed, but the only way I can get the proper filtering is to
use the two variables, BookID and ChapterID, together in the one SQL
statement.
I know I am missing something silly in the Sub procedure, but I can't figure
it out.
Thanks in advance for any nudges in the right direction,
Gary
Hi Garry,
I did look a long time and did not see it, the strange thing is of course
that it works with combobox 1 and not with combobox 2.
While I asume they are completly the same with the only difference the extra
parameter in the second.
(I never wrote it in the way you did, but looking at the documentation I see
no errors).
Did you debug it?
I myself add always while debugging just something as
dim myfirsttest as string = cmbChapter.Sele ctedValue daVerse.SelectC ommand.Paramete rs("ChapterID") .Value = cmbChapter.Sel ectedValue
dim mysecondtest as string = cmbBook.Selecte dValue daVerse.SelectC ommand.Paramete rs("BookID").Va lue = cmbBook.Select edValue
I hope this helps, and message back if the values are correct OK?
Cor
Cor,
I don't get any 'ERRORS' when I run it in Debug mode.
A little more information:
cmbBook displays 73 items, (the names of the Books in the Douay-Rheims
Bible)
cmbChapter displays up to 150 items, (the number of Chapters according to
which Book is selected in cmbBook), this works fine.
cmbVerse should display up to 176 items, (the number of Verses according to
which Chapter AND Book are selected in the previous ComboBoxes), this part
is not filtering correctly. It does not generate any errors in the program.
When I run the SQL statement in the Query Builder, (I have to enter the two
parameters), the resulting table is correctly filtered and displays the
number of verses according to the Book AND Chapter selected. This is also
the result when I run Preview Data, (and have to enter the parameters
manually).
I am stuck at trying to pass the TWO parameters to
dsVerse.SelectC ommand.CommandT ext...
Can it be done with one line, not two like this:
daVerse.SelectC ommand.Paramete rs("ChapterID") .Value =
cmbChapter.Sele ctedValue
daVerse.SelectC ommand.Paramete rs("BookID").Va lue = cmbBook.Selecte dValue
Thanks,
Gary
Hi Bo,
Normaly I only find this in the documentation (read SQL where OLeDB when it
is in your case SQL)
' ...
' create myDataSet and myDataAdapter
' ...
myDataAdapter.S electCommand.Pa rameters.Add("@ CategoryName",
OleDbType.VarCh ar, 80).Value = "toasters"
myDataAdapter.S electCommand.Pa rameters.Add("@ SerialNum",
OleDbType.Integ er).Value = 239
myDataAdapter.F ill(myDataSet)
But I found your methode also, but if you realy stuck, maybe you can try
this to test
(debugs very easy)
mystring as string = "SELECT DISTINCT tblVerse.Verse, tblVerse.VerseI D,
tblVerseText.Ve rseID AS
VerseKey, tblVerseText.Ch apterID AS ChapterKey, tblVerseText.Bo okID AS
BookKey
FROM tblVerse INNER JOIN tblVerseText ON
tblVerse.VerseI D = tblVerseText.Ve rseID
WHERE tblVerseText.Ch apterID ='" & cmbChapter.Sele ctedValue & "' AND
(tblVerseText.B ookID = '"
& cmbBook.Selecte dValue & "' ORDER BY tblVerse.VerseI D"
dim daverse as new dataadapter(mys tring, myconnection)
daverse.fill(my dataset)
And then when it works make it nice code.
Maybe it helps,
Cor I don't get any 'ERRORS' when I run it in Debug mode.
A little more information:
cmbBook displays 73 items, (the names of the Books in the Douay-Rheims Bible)
cmbChapter displays up to 150 items, (the number of Chapters according to which Book is selected in cmbBook), this works fine.
cmbVerse should display up to 176 items, (the number of Verses according
to which Chapter AND Book are selected in the previous ComboBoxes), this part is not filtering correctly. It does not generate any errors in the
program. When I run the SQL statement in the Query Builder, (I have to enter the
two parameters), the resulting table is correctly filtered and displays the number of verses according to the Book AND Chapter selected. This is also the result when I run Preview Data, (and have to enter the parameters manually).
I am stuck at trying to pass the TWO parameters to dsVerse.SelectC ommand.CommandT ext...
Can it be done with one line, not two like this:
daVerse.SelectC ommand.Paramete rs("ChapterID") .Value = cmbChapter.Sele ctedValue daVerse.SelectC ommand.Paramete rs("BookID").Va lue = cmbBook.Selecte dValue This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Tim Graichen |
last post by:
Good morning,
I have a sub-form that displays records from a table as a continuous form.
The table has several hundred records, but the subform only displays five or
six records. The records do include a date field.
How can I force the sub form to display the most recent dates by default,
verses forcing the user to scroll through all of the records to the bottom
of the form in order to view the most recent entry or to add a new entry...
|
by: Matt K. |
last post by:
Hi there,
I have a form in an Access project that contains a subform which
displays the results of a query of the style "select * from
where = #a certain date#". In the main part of the form
the user can change the date, which will force a requery in the
subform to bring up records from the date selected.
My question is this... The query in the subform is a very simple one,
with only three fields being returned. In the interest of...
|
by: Robin S. |
last post by:
I tried to ask this question several days ago, but I didn't explain my
application correctly.
Basically I want to have one record from table "A" and I want to display,
say, 5 records from table "B" which are specified by the one record from
table "A"... And all on the same form. I do not want to use a subform. The
record fields from table "B" must be displayed in text boxes with the record
fields from the single record from table "A".
...
|
by: Robert |
last post by:
Hello Accessors
I have some reports created in Access that are very good for what they do.
However, it seems to me that when you are displaying information you don't
need to print out that a printer-friendly report is not the best way to go.
So, I tried converting one of my Access reports to an Access form. I
selected the continuous view to allow displaying multple records but when I
went to define my sorting and grouping there was none...
|
by: tdmailbox |
last post by:
I have a form with a child form. In the child form there is a list of
names that can grow quite large. On the parent form I want to display
the first name from the child form. I set up a test box that is
populated with the code
=subfrm_media_review_sec_party.Form!first_name & " " &
subfrm_media_review_sec_party.Form!last_name
It works except that when I flip through the names it populates the
parent form with the name of what ever...
| |
by: Susan Bricker |
last post by:
Greetings.
I am having trouble populating text data that represents data in my
table. Here's the setup:
There is a People Table (name, address, phone, ...)
peopleID = autonumber key
There is a Judge Table (information about judges)
judgeID = autonumber key
|
by: Lyn |
last post by:
I need some guidance for a technique that will allow me to accomplish the
following...
I have a table in which each record contains a photograph. I would like to
display in a form a thumbnail size version of each photograph horizontally
across the form, then have the photgraphs "word wrap" (picture wrap ?) at
the right end of the form onto the next "line" of photographs. Does anyone
know how this can be done?
Obviously, displaying...
|
by: darrel |
last post by:
Hi there, good day! i need some help in displaying my records,,, my assignment is i have to display a database records in a labels.
Its like this in my database i have a table called "SUBJECTS" that is consists of 4 fields, SUBJECT CODE, SUBJECT, TYPE, & UNITS, i have input their all the data for my fields that have unique identifier. My problem i dont know how to display in my form.
No in my form i have several of labels. in each...
|
by: dheroan |
last post by:
Hi there,
I'm fairly new to using databases with VB .NET. I'm currently working on an application using a Microsoft Access database as a data source. I have created a form to display the fields for each record in a particular table (using the feature that allows you to drag and drop a field from a table in the database onto the form, automatically attaching a BindingNavigator and TableAdapter and all that jazz to it). As you probably know,...
|
by: John Kirkpatrick |
last post by:
Hi all,
I am having difficulty displaying records on a frontend MS Access 2000 form using a MySQL backend. The following code works well with the Jet database engine but doesn't work properly using the MySQL backend database. All records are displayed on the form using the Jet, but only one record appears using MySQL. Perhaps it just needs some tweaking to work with MySQL. Any advice would be great. Thanks
Function HelpDesc(HelpFrm As...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |