User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the ASP section within the Web Development category of DaniWeb, a massive community of 361,618 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,149 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our ASP advertiser: Lunarpages ASP Web Hosting
Views: 845 | Replies: 5 | Solved
Reply
Join Date: Aug 2007
Posts: 98
Reputation: GLT is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
GLT GLT is offline Offline
Junior Poster in Training

Dreamweaver - displaying data from a recordset

  #1  
Mar 18th, 2008
Hi guys!

I was wondering if any of you guys would be able to help solve what is probably a simple problem....

I am using dreamweaver / asp/ access to create a dynamic web application. I have created a record set which queries the database and displays the results. The recordset searches for a product id which is inserted by the user, the product details are then displayed. I somehow can only get the first record in the database to display in the dynamic table. This record is not even searched for it is just there already when i preview the page in the browser then when I enter another ID nothing happens.

here is my code :-

  1. <%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
  2. <!--#include file="Connections/dbtest.asp" -->
  3. <%
  4. Dim rs_search__MMColParam
  5. rs_search__MMColParam = "1"
  6. If (Request.Form("ProductID") <> "") Then
  7. rs_search__MMColParam = Request.Form("ProductID")
  8. End If
  9. %>
  10. <%
  11. Dim rs_search
  12. Dim rs_search_numRows
  13.  
  14. Set rs_search = Server.CreateObject("ADODB.Recordset")
  15. rs_search.ActiveConnection = MM_dbtest_STRING
  16. rs_search.Source = "SELECT * FROM product WHERE ProductID = " + Replace(rs_search__MMColParam, "'", "''") + " ORDER BY ProductID ASC"
  17. rs_search.CursorType = 0
  18. rs_search.CursorLocation = 2
  19. rs_search.LockType = 1
  20. rs_search.Open()
  21.  
  22. rs_search_numRows = 0
  23. %>
  24. <%
  25. Dim Repeat1__numRows
  26. Dim Repeat1__index
  27.  
  28. Repeat1__numRows = 10
  29. Repeat1__index = 0
  30. rs_search_numRows = rs_search_numRows + Repeat1__numRows
  31. %>
  32. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  33. <html>
  34. <head>
  35. <title>search</title>
  36. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  37. </head>
  38.  
  39. <body>Insert product ID you wish to search for:-
  40. <form method="POST" name="formsearch" id="formsearch">
  41. <table width="528" height="136" border="1">
  42. <tr>
  43. <td width="153">productID</td>
  44. <td width="359"><input name="txtProductID" type="text" id="txtProductID" size="50"></td>
  45. <td><input name="btnsearch" type="submit" id="btnsearch" value="search"></td>
  46. </tr>
  47. </table>
  48.  
  49. <input type="hidden" name="MM_search" value="formsearch">
  50. </form>
  51. <p>&nbsp;</p>
  52.  
  53. <table border="1">
  54. <tr>
  55. <td>ProductID</td>
  56. <td>Product</td>
  57. <td>Price</td>
  58. </tr>
  59. <% While ((Repeat1__numRows <> 0) AND (NOT rs_search.EOF)) %>
  60. <tr>
  61. <td><%=(rs_search.Fields.Item("ProductID").Value)%></td>
  62. <td><%=(rs_search.Fields.Item("Product").Value)%></td>
  63. <td><%= FormatCurrency((rs_search.Fields.Item("Price").Value), 2, -2, -2, -2) %></td>
  64. </tr>
  65. <%
  66. Repeat1__index=Repeat1__index+1
  67. Repeat1__numRows=Repeat1__numRows-1
  68. rs_search.MoveNext()
  69. Wend
  70. %>
  71. </table>
  72. </body>
  73. </html>
  74. <%
  75. rs_search.Close()
  76. Set rs_search = Nothing
  77. %>

Any ideas would be greatly appreciated! Thanks!!!

GLT
Last edited by peter_budo : Mar 27th, 2008 at 2:42 am. Reason: Keep It Organized - please use [code] tags
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Aug 2007
Posts: 98
Reputation: GLT is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
GLT GLT is offline Offline
Junior Poster in Training

Re: Dreamweaver - displaying data from a recordset

  #2  
Mar 18th, 2008
It seems to be that my default value in the recordset is set to '1' , I changed this to '0' and it said 'no data', this is because there is not product with the Id of 0. All i want to do is search for an ID and then it is displayed to the user not just what is in the default value. I have tried not putting anything in the default value and Dreamweaver wont let me.

Any ideas???
Reply With Quote  
Join Date: Feb 2008
Posts: 135
Reputation: TobbeK is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 3
TobbeK TobbeK is offline Offline
Junior Poster

Re: Dreamweaver - displaying data from a recordset

  #3  
Mar 18th, 2008
Try to close the variable with a single quote 'rs_search__MMColParam = "1" and test. It is set to the static value "1" for some reason. It is possible that value overrides the input.

Test this:
Dim rs_search__MMColParam
'rs_search__MMColParam = "1"
If (Request.Form("ProductID") <> "") Then 
rs_search__MMColParam = Request.Form("ProductID")
End If

.... or try to contain the variable within the (If then).

Dim rs_search__MMColParam
If (Request.Form("ProductID") <> "") Then 
rs_search__MMColParam = Request.Form("ProductID")
ElseIf (Request.Form("ProductID") = "") Then
rs_search__MMColParam = "1"
End If

Another option that maybe solve the thing is to change the name to txtProductID

Dim rs_search__MMColParam
rs_search__MMColParam = "1"
If (Request.Form("txtProductID") <> "") Then 
rs_search__MMColParam = Request.Form("txtProductID")
End If
Last edited by TobbeK : Mar 18th, 2008 at 8:51 pm.
Reply With Quote  
Join Date: Aug 2007
Posts: 98
Reputation: GLT is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
GLT GLT is offline Offline
Junior Poster in Training

Re: Dreamweaver - displaying data from a recordset

  #4  
Mar 25th, 2008
I still cant get it to work.

I think its because I have a default value of 1 but i have to put something into the default value so what should i do??

all i want to do is create a simple search and results page, the user will enter an id and the details are displayed.

any ideas would be greatly apprieciated!
Thanks!
GLT
Reply With Quote  
Join Date: Aug 2007
Posts: 98
Reputation: GLT is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
GLT GLT is offline Offline
Junior Poster in Training

Re: Dreamweaver - displaying data from a recordset

  #5  
Mar 25th, 2008
this is the code i have at the minute:-

  1. <%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
  2. <!--#include file="Connections/dbtest.asp" -->
  3. <%
  4. Dim rs_search__MMColParam
  5. If (Request.Form("ProductID") <> "") Then
  6. rs_search__MMColParam = Request.Form("ProductID")
  7. ElseIf (Request.Form("ProductID") = "") Then
  8. rs_search__MMColParam = "1"
  9. End If
  10. %>
  11. <%
  12. Dim rs_search
  13. Dim rs_search_numRows
  14.  
  15. Set rs_search = Server.CreateObject("ADODB.Recordset")
  16. rs_search.ActiveConnection = MM_dbtest_STRING
  17. rs_search.Source = "SELECT * FROM product WHERE ProductID = " + Replace(rs_search__MMColParam, "'", "''") + " ORDER BY ProductID ASC"
  18. rs_search.CursorType = 0
  19. rs_search.CursorLocation = 2
  20. rs_search.LockType = 1
  21. rs_search.Open()
  22.  
  23. rs_search_numRows = 0
  24. %>
  25. <%
  26. Dim Repeat1__numRows
  27. Dim Repeat1__index
  28.  
  29. Repeat1__numRows = 10
  30. Repeat1__index = 0
  31. rs_search_numRows = rs_search_numRows + Repeat1__numRows
  32. %>
  33. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  34. <html>
  35. <head>
  36. <title>search</title>
  37. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  38. </head>
  39.  
  40. <body>Insert product ID you wish to search for:-
  41. <form method="POST" name="formsearch" id="formsearch">
  42. <table width="528" height="136" border="1">
  43. <tr>
  44. <td width="153">productID</td>
  45. <td width="359"><input name="txtProductID" type="text" id="txtProductID" size="50"></td>
  46. <td><input name="btnsearch" type="submit" id="btnsearch" value="search"></td>
  47. </tr>
  48. </table>
  49.  
  50. <input type="hidden" name="MM_search" value="formsearch">
  51. </form>
  52. <p>&nbsp;</p>
  53. <p>results:-</p>
  54. <table border="1">
  55. <tr>
  56. <td width="87">ProductID</td>
  57. <td width="87">Product</td>
  58. <td width="87">Price</td>
  59. </tr>
  60. <% While ((Repeat1__numRows <> 0) AND (NOT rs_search.EOF)) %>
  61. <tr>
  62. <td><%=(rs_search.Fields.Item("ProductID").Value)%></td>
  63. <td><%=(rs_search.Fields.Item("Product").Value)%></td>
  64. <td><%=(rs_search.Fields.Item("Price").Value)%></td>
  65. </tr>
  66. <%
  67. Repeat1__index=Repeat1__index+1
  68. Repeat1__numRows=Repeat1__numRows-1
  69. rs_search.MoveNext()
  70. Wend
  71. %>
  72. </table>
  73. </body>
  74. </html>
  75. <%
  76. rs_search.Close()
  77. Set rs_search = Nothing
  78. %>
Last edited by peter_budo : Mar 27th, 2008 at 2:42 am. Reason: Keep It Organized - please use [code] tags
Reply With Quote  
Join Date: Aug 2007
Posts: 98
Reputation: GLT is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
GLT GLT is offline Offline
Junior Poster in Training

Re: Dreamweaver - displaying data from a recordset

  #6  
Mar 25th, 2008
I solved it myself! It was my fault!

I had to change the code to point to the text box in the search form not the field in the database table! I didnt realise it was doing this as they are both called the same except the text box is called txtProductID not ProductID.

Here is the new code for the section i changed:-

  1. Dim rs_search__MMColParam
  2. rs_search__MMColParam = "1"
  3. If (Request.Form("txtProductID") <> "") Then
  4. rs_search__MMColParam = Request.Form("txtProductID")
  5. End If

Thanks for you help!!
GLT
Last edited by peter_budo : Mar 27th, 2008 at 2:42 am. Reason: Keep It Organized - please use [code] tags
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb ASP Marketplace
Thread Tools Display Modes

Other Threads in the ASP Forum

All times are GMT -4. The time now is 6:16 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC