473,386 Members | 1,702 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

query an access database

6
i would like to know how to query a database so that if a category from the dropdown menu is selected it will display all the records found on the table.
thank you very much.
Here is the table from the database:

Description Design Type Price
Necklace Spiral 18 ct Gold £1,725.99
Necklace Chain 9 ct Gold £150.75
Ring Sapphire 18 ct Gold £975.00
Necklace Loop 9 ct Gold £199.50
Ring Opal 18 ct Gold £225.50
Ring Ruby Silver £180.00
Necklace Sapphire Silver £375.00
Ring Diamond Silver £379.99
Watch Wrist Platinum £99.99
Watch Wrist Rolex £2,299.99

and here the code:
Expand|Select|Wrap|Line Numbers
  1. <%
  2. Dim Connection, Recordset
  3. Dim sSQL, sConnString
  4.  
  5. sSQL="SELECT * FROM table1"
  6.  
  7.  
  8. sConnString="PROVIDER=Microsoft.Jet.OLEDB.4.0;" &_
  9. "Data Source=" & Server.MapPath("Jewellerydb.mdb")
  10.  
  11.  
  12. Set connection = Server.CreateObject("ADODB.Connection")
  13. Set Recordset = Server.CreateObject("ADODB.Recordset")
  14.  
  15. connection.Open sConnString
  16. recordset.Open sSQL,connection
  17.  
  18. If request.form("dropdown")="Watch" Then 
  19. Response.Write recordset("Design") & " " & recordset("Type") & " " & recordset("Price")
  20. ElseIf request.form("dropdown")="Necklace" Then 
  21. Response.Write recordset("Design")
  22. ElseIf request.form("dropdown")="Ring" Then 
  23. Response.Write recordset("Price")
  24. End if
  25.  
  26. Recordset.Close
  27. Connection.Close
  28. Set Recordset = Nothing
  29. Set Connection = Nothing
  30. %>
Thank you for your help!
Jun 18 '07 #1
3 1642
jhardman
3,406 Expert 2GB
i would like to know how to query a database so that if a category from the dropdown menu is selected it will display all the records found on the table.
thank you very much.
Here is the table from the database:

Description Design Type Price
Necklace Spiral 18 ct Gold £1,725.99
Necklace Chain 9 ct Gold £150.75
Ring Sapphire 18 ct Gold £975.00
Necklace Loop 9 ct Gold £199.50
Ring Opal 18 ct Gold £225.50
Ring Ruby Silver £180.00
Necklace Sapphire Silver £375.00
Ring Diamond Silver £379.99
Watch Wrist Platinum £99.99
Watch Wrist Rolex £2,299.99

and here the code:
Expand|Select|Wrap|Line Numbers
  1. <%
  2. Dim Connection, Recordset
  3. Dim sSQL, sConnString
  4.  
  5. sSQL="SELECT * FROM table1"
  6.  
  7.  
  8. sConnString="PROVIDER=Microsoft.Jet.OLEDB.4.0;" &_
  9. "Data Source=" & Server.MapPath("Jewellerydb.mdb")
  10.  
  11.  
  12. Set connection = Server.CreateObject("ADODB.Connection")
  13. Set Recordset = Server.CreateObject("ADODB.Recordset")
  14.  
  15. connection.Open sConnString
  16. recordset.Open sSQL,connection
  17.  
  18. If request.form("dropdown")="Watch" Then 
  19. Response.Write recordset("Design") & " " & recordset("Type") & " " & recordset("Price")
  20. ElseIf request.form("dropdown")="Necklace" Then 
  21. Response.Write recordset("Design")
  22. ElseIf request.form("dropdown")="Ring" Then 
  23. Response.Write recordset("Price")
  24. End if
  25.  
  26. Recordset.Close
  27. Connection.Close
  28. Set Recordset = Nothing
  29. Set Connection = Nothing
  30. %>
Thank you for your help!
You might want to study up on sql.

I don't see anything that would cause an error in the above code, but I don't see why you would code like that. As you posted you did not make a question. Do you have a question, or did you just want to post your code sample?

Jared
Jun 18 '07 #2
Ninio
6
You might want to study up on sql.

I don't see anything that would cause an error in the above code, but I don't see why you would code like that. As you posted you did not make a question. Do you have a question, or did you just want to post your code sample?

Jared
Hi, and thank you for replying so soon.
The actual code i posted had no errors, in fact it works very well indeed.
As you can see I have a table in the database which has 4 columns and 10 rows.
So far what i can do is to connect to the database and get the drop down options to display all records. But what i need to do know is how to query the table for specific content. For instance request.form("dropdown")="Watch" to display only the rows that have watch in the description column, request.form("dropdown")="Ring" to display only the rows that have ring in the description column and so on.
I have looked around and tried different approaches but so far nothing has worked.
Thank you for your help
Jun 18 '07 #3
jhardman
3,406 Expert 2GB
try this
Expand|Select|Wrap|Line Numbers
  1. sSQL="SELECT * FROM table1"
  2.  
  3. sSQL = sSQL & " WHERE description LIKE '" & request.form("dropdown") & "'"
  4.  
  5. 'if request.form("dropdown") said "watch" then
  6. 'sSQL now says, "SELECT * FROM table1 WHERE description LIKE 'watch' 
  7.  
  8. sConnString="PROVIDER=Microsoft.Jet.OLEDB.4.0;" &_
  9. "Data Source=" & Server.MapPath("Jewellerydb.mdb")
  10.  
  11. Set connection = Server.CreateObject("ADODB.Connection")
  12. Set Recordset = Server.CreateObject("ADODB.Recordset")
  13.  
  14. connection.Open sConnString
  15. recordset.Open sSQL,connection
Jun 18 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

15
by: Rolan | last post by:
There must be a way to enhance the performance of a query, or find a plausible workaround, but I seem to be hitting a wall. I have tried a few tweaks, however, there has been no improvement. ...
3
by: rhobson2 | last post by:
Hello, I wrote a database applicaiton using Access XP (2002) and everything has been working good for the client until they purchased a couple of new computers with Access 2003. The meetings...
2
by: Bob Alston | last post by:
If you have an access form with record source being a straightforward query and where clause in the form definition, will the query be sent to the back end jet/Access database and executed there,...
3
by: mnjkahn via AccessMonster.com | last post by:
I'm running Access 2003, modifying a query that has over 45 fields. When I right click on the field name in Query Design View, and then click Build, Access crashes before the Build window...
2
by: existential.philosophy | last post by:
This is a new problem for me: I have some queries that open very slowly in design view. My benchmark query takes about 20 minutes to open in design view. That same query takes about 20 minutes...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
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,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.