Querying a database (in over my head)

Results 1 to 4 of 4

Thread: Querying a database (in over my head)

  1. #1
    Don Makoviney Guest

    Default Querying a database (in over my head)

    I have dabbled in ASP but have been assigned a project that is way over my head.<BR><BR>I have to create pages that pull some information from a database - and I figured that out using the source code below - and it works fine. But now I also need to just pull specific records that fit one of five departments and then 1 of 5 categories.<BR><BR>For instance a typical query to the database would be something like SELECT * WHERE DEPARTMENT= APPAREL & CATEGORY= MEN. . . .and then it would display the records in the format as coded below. . . .which means that the actual category and department fields won&#039t be shown in the results. . . .but I have that part figured out. . .<BR>I haven&#039t been able to find any good resources on querying like that. . . . .none that I have seen have gotten right to the point and simply confuse me. . . . <BR><BR>If my question doesn&#039t make sense - in simplest terms . . .I just need help making the query. It is a fixed query on the page - something like SELECT * WHERE DEPARTMENT= APPAREL & CATEGORY= MEN - although I know that&#039s probably not the correct syntax. . .<BR><BR>Thanks in advance for your help. . . . .<BR><BR>-Don Makoviney<BR><BR>&#060;HTML&#062;<BR>&#060;HEAD&#0 62;<BR>&#060;TITLE&#062;Contact information&#060;/TITLE&#062;<BR>&#060;/HEAD&#062;<BR>&#060;BODY&#062;<BR><BR>&#060;%<BR> Dim objConn<BR> Dim objRec<BR><BR> Set objConn = Server.CreateObject ("ADODB.Connection")<BR> Set objRec = Server.CreateObject ("ADODB.Recordset")<BR><BR> objConn.Open "DSN=Contact"<BR><BR> objRec.Open "Contact", objConn, 0, 1, 2<BR><BR> While Not objRec.EOF<BR> Response.Write("&#060;table border=1&#062;")<BR> Response.Write("&#060;tr&#062;")<BR> Response.Write(" &#060;td width=300&#062;" & objRec("Name") & "&#060;/td&#062;")<BR> Response.Write(" &#060;td width=300&#062;" & objRec("Phone") & "&#060;/td&#062;")<BR> Response.Write("&#060;/tr&#062;")<BR> Response.Write("&#060;tr&#062;")<BR> Response.Write(" &#060;td width=600 colspan=2&#062;" & objRec("Description") & "&#060;/td&#062;")<BR> Response.Write("&#060;/tr&#062;")<BR> objRec.MoveNext<BR> Wend<BR>Response.Write("&#060;/table&#062;")<BR> objRec.Close<BR> objConn.Close<BR> Set objRec = Nothing<BR> Set objConn = Nothing<BR><BR>%&#062;<BR><BR>&#060;/BODY&#062;<BR>&#060;/HTML&#062;

  2. #2
    Join Date
    Dec 1969
    Posts
    1,388

    Default RE: Querying a database (in over my head)

    Not sure if this is exactly what you&#039re looking for, but the sql statement would be along these lines:<BR>SQL = "SELECT * FROM contact WHERE department= apparel AND category = men"<BR><BR>To use this query, replace:<BR>objRec.Open "Contact", objConn, 0, 1, 2<BR>with:<BR>objRec.Open SQL, objConn, 0, 1, 2 (I personally use just &#039 3, 3&#039 in the open statemnet, but your needs may vary). Hope this helps.<BR><BR><BR>

  3. #3
    Steve Rowson Guest

    Default RE: Querying a database (in over my head)

    Lets say you have two drop-down boxes on a form - one called Department which contains your list of departments and one called Gender which contains your list of sexes. A user selects &#039apparel&#039 and &#039men&#039 from the two drop down lists. When they hit the submit button it passes the data to your asp page. You retrieve the values &#039apparel&#039 and &#039men&#039 using Request.QueryString if you used Get as the posting method of the form on the previous page.<BR>So you set a varible on your asp page that says<BR>&#060;%ReqDepartment = Request.QueryString("Department")%&#062;<BR>&#060; %ReqGender = Request.QueryString("Gender")<BR>I am now assuming you have two fields called Department and Gender in a table called Products<BR>You now have two variables on this page holding &#039apparel&#039 and &#039men&#039 respectively.<BR>You pass these parameters into your SQL query as follows:<BR>SQL = "SELECT * FROM Products WHERE Department = &#039" & ReqDepartment & "&#039 AND Category = &#039" & ReqGender & "&#039"<BR>This is how you pass text parameters to text fields. To pass number parameters to number fields you omit the pair of double inverted commas around the parameter name.<BR>

  4. #4
    Don Makoviney Guest

    Default RE: Querying a database (in over my head)

    Thanks both - you helped alot. . . .<BR><BR>Don Makoviney


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •