Connecting Tech Pros Worldwide Help | Site Map

access with classic asp

Member
 
Join Date: Jul 2008
Posts: 123
#1: Oct 6 '09
im have tables in access,Customer,Products and Order Table...

Customer Table:
Expand|Select|Wrap|Line Numbers
  1. Cust_ICNumber (PK)
  2. Cust_Name
  3. Cust_Address
  4. Cust_PrimaryNumber
  5. Cust_SecondaryNumber
  6. Cust_Company
  7. Cust_CompanyType
  8.  
Products Table
Expand|Select|Wrap|Line Numbers
  1. Product_ID (PK)
  2. Product_Name
  3. Product_Price
  4. Product_Picture
  5.  
Order Table
Expand|Select|Wrap|Line Numbers
  1. Order_ID(PK)
  2. Product_ID(FK)
  3. Order_Quantity
  4. Order_Date
  5. Customer_ICNumber (FK)
  6. Total_Price
  7.  
I intend to output bill (a classic asp file) from order table which will display Order ID,Product Name,Product Price, Customer Name,Customer Address,Order Date.
I wondering if this sql is correct
Expand|Select|Wrap|Line Numbers
  1. SELECT tCustomer.Cust_Name, tCustomer.Cust_Address, tProducts.Product_Name,tOrder.Order_Quantity, tOrder.Order_Date,tOrder.Order_ID, tOrder_Total_Price FROM (((Order AS tOrder LEFT JOIN Customer AS tCustomer ON tOrder.Customer_ICNumber = tCustomer.Cust_ICNumber) LEFT JOIN Products AS tProducts ON tOrder.Product_ID = tProducts.Product_ID);
  2.  
Another question is do i need to create the relationship in the database when using classic asp...Sorry for this question,i know it is sound silly but i just want to confirm it as im very new at this.
jhardman's Avatar
Moderator
 
Join Date: Jan 2007
Location: logan, utah
Posts: 2,690
#2: Oct 7 '09

re: access with classic asp


You have a pretty complicated SQL statement for someone who is new at this! In order to make sure it does what you want you need to test the query in a query analyzer - I haven't used Access in a while, but you should be able to send this code to access and have access spit out a sample response. Beyond that, an access expert would be better equipped to answer you.

For your other question, the ASP will work whether the relationship is defined or not, but it is a good idea to define the relationship - especially for purposes of adding and deleting records. For example, if the relationship is defined, it may prevent you from deleting the wrong record.

Jared
Member
 
Join Date: Jul 2008
Posts: 123
#3: Oct 8 '09

re: access with classic asp


Im wondering if there is any way to retrieve record from three different table(table as above). Because I have been trying to use the sql I created and keep getting error.
GazMathias's Avatar
Expert
 
Join Date: Oct 2008
Location: Bristol, United Kingdom
Posts: 143
#4: Oct 8 '09

re: access with classic asp


Does your query work in the Query Designer in Access? If not it should highlight what is wrong.

When you've finished, view the query in SQL view and copy it to your asp page and run it. You should get the same results.

Have you written the HTML / VB Script (I assume) to display this data?

Gaz.
Member
 
Join Date: Jul 2008
Posts: 123
#5: Oct 9 '09

re: access with classic asp


Im didnt try in on Query Designer yet...Yes i have written the html but im using javascript to display the data
Member
 
Join Date: Jul 2008
Posts: 123
#6: Oct 9 '09

re: access with classic asp


this is my code for the html/javascript...

Expand|Select|Wrap|Line Numbers
  1. <%@language="javascript"%>
  2. <html>
  3. <%
  4.  
  5. var DSN = "C:/Inetpub/wwwroot/MyBakery.mdb";
  6. var Conn = Server.CreateObject("ADODB.Connection");
  7. Conn.Provider = "Microsoft.Jet.OLEDB.4.0";
  8. Conn.Open(DSN);
  9.  
  10. sql = "SELECT * FROM Customer INNER JOIN Order ON Customer.Customer_ICNumber = Order.Customer_ICNumber";
  11.  
  12. rs = Server.CreateObject("ADODB.Recordset");
  13. rs.Open(sql,Conn);
  14.  
  15. Response.Write("Delish Cakes and Pastries");
  16.  
  17. out = "<table>";
  18. out+="<tr><td>Name:</td><td>" + rs("Cust_Name") + "</td><td></td><td>Order ID:</td><td>" 
  19. out+= rs("Order_ID") + "</td></tr>";
  20. out+="<tr><td>Address:</td><td>" + rs("Cust_Address") + "</td><td></td><td>Order Date:</td><td>"
  21. out += rs("Order_Date") + "</td></tr>";
  22. out+="<h2>Orders:</h2><p>"
  23. out+="<tr><td><pre>Product</pre></td><td>Quantity</td><td>Price</td></tr>"
  24. out+="<tr><td>" + rs("Product_Name") + "</td><td>"
  25. out+=rs("Order_Quantity") + "</td><td>"
  26. out+=rs("Product_Price") + "</td></tr>";
  27. out+="</table>";
  28.  
  29. Response.write(out);
  30.  
  31. %>
  32.  
  33. </body>
  34. </html>
  35.  
CroCrew's Avatar
Expert
 
Join Date: Jan 2008
Location: Michigan
Posts: 338
#7: Oct 9 '09

re: access with classic asp


What is the error your getting?
CroCrew's Avatar
Expert
 
Join Date: Jan 2008
Location: Michigan
Posts: 338
#8: Oct 9 '09

re: access with classic asp


Hello puT3,

Looks like one of your “main” problems is that you’re using a reserved word as your table name. The word “Order” is a reserved SQL command and should not be used as a table or field name.

Another problem I can see is that you HTML is off too. You have tags out side of their designated usage spots; if you understand what I am saying.

Below is a VB version of your JavaScript version using the table name “Orders” and not “Order”.

Have a look and give it a try.

Expand|Select|Wrap|Line Numbers
  1. <% 
  2.     Set adoCon = Server.CreateObject("ADODB.Connection") 
  3.     adoCon.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("C:/Inetpub/wwwroot/MyBakery.mdb")  
  4.     Set rsCustomers = Server.CreateObject("ADODB.Recordset") 
  5.  
  6.     SQL = "SELECT * FROM Customer a INNER JOIN Orders  b ON (a.Customer_ICNumber = b.Customer_ICNumber)" 
  7.     rsCustomers.CursorType = 2 
  8.     rsCustomers.LockType = 3 
  9.     rsCustomers.Open SQL, adoCon 
  10.  
  11.     Response.Write("Delish Cakes and Pastries")
  12.     Response.Write("<table>")
  13.     Response.Write("<tr><td>Name:</td><td>" & rsCustomers("Cust_Name").value & "</td><td>&nbsp;</td><td>Order ID:</td><td>" & rsCustomers("Order_ID").value & "</td></tr>")
  14.     Response.Write("<tr><td>Address:</td><td>" & rsCustomers("Cust_Address".value & "</td><td>&nbsp;</td><td>Order Date:</td><td>" & rsCustomers("Order_Date").value & "</td></tr>")
  15.     Response.Write("<tr><td colspan='5'><h2>Orders:</h2></td></tr>")
  16.     Response.Write("<tr><td colspan='2'><pre>Product</pre></td><td>Quantity</td><td>Price</td></tr>")
  17.     Response.Write("<tr><td colspan='2'>" & rsCustomers("Product_Name").value & "</td><td>" & rsCustomers("Order_Quantity").value & "</td><td>" & rsCustomers("Product_Price").value & "</td></tr>")
  18.     Response.Write("</table>")
  19. %> 
  20.  
Hope this helps,
CroCrew~
Member
 
Join Date: Jul 2008
Posts: 123
#9: Oct 10 '09

re: access with classic asp


it helps, thanks for letting me know the error...
Reply