locked
Classic ASP RRS feed

  • Question

  • User-817583793 posted

    Hello,

    I've inherited an asp file and I'm trying to make a few updates to it. I'm trying to add a conditional statement that will check a database column for a specified cell value. If the cell value is found then the content should display; however, if the value is not found then the content should not display. 

    Thank you.

    Monday, April 8, 2019 12:07 AM

All replies

  • User690216013 posted

    I've inherited an asp file and I'm trying to make a few updates to it. I'm trying to add a conditional statement that will check a database column for a specified cell value. If the cell value is found then the content should display; however, if the value is not found then the content should not display. 

    Then what's the question here, or you just want someone to write the code for you?

    Monday, April 8, 2019 12:20 AM
  • User-817583793 posted

    Lextm, 

    I'm not looking for someone to write the code but to point me in a direction to get a better understanding. 

    I have not worked with asp but I am trying to learn. During my searches, I have not come across a resource online that is similar to what I am trying to achieve-- that's why I turned to the forum.

    Monday, April 8, 2019 1:39 PM
  • User-848649084 posted

    Hi eb27,

    What is your exact requirement? Could you share sample database fields and which type of data you want to match with the database? You want to match file textbox, table or gridview value with database table? 

    Regards,

    Jalpa.

    Tuesday, April 9, 2019 2:50 AM
  • User-817583793 posted

    Hello Jalpa, 

    Requirement: 

    1. 1) Search a database to locate any cell values that are equal to Y
    2. 2) Display only the record that contains the Y
    3. 3) Skip and don't display those records that do not contain Y

    Sample fields

    The field Trainers was created to assign a value to indicate which individual supplies resources. 

    trainers resources user_id first_name
    4959495040 Jenny
    Y healthy life style, running is for fun online materials 9685849401 Micah
    4756399472 Sybil
    Y healthy life style, running is for fun online materials 5903948227 Joseph

    You want to match file textbox, table or gridview value with database table? 

    I'm not sure. I need to read up on the difference between the above. 

    Desired result …. web page [only show the results based on the value of Y]

    Name: Micah

    Id: 9685849401

    Resources: healthy life style, running is for fun online materials

    Name: Joseph

    Id: 5903948227

    Resources: healthy life style, running is for fun online materials

    Thank you for taking time out to assist.

    Tuesday, April 9, 2019 1:49 PM
  • User-848649084 posted

    Hi,

    You could get data from the database based on textbox selected value.

    asp code:

    <html>
    <body> 
    <form method="post" name="form">
    First Name: <input type="text" name="fname"><br><br />
    <input type="submit" value="Submit">
    <%
    Dim objConn
    Set objConn = Server.CreateObject("ADODB.Connection")
    objConn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=D:\aspsamplesite\Database1.mdb;"
    objConn.Open
    f_name=request.form("fname") Set str = objConn.execute("SELECT * FROM Table1 WHERE fname= '" & f_name & "';")
    Response.Write("<table>") If str.BOF And str.EOF Then ' No data Else Do While (Not str.EOF) Response.Write "<tr><td>" & str("fname") & "</td><td>" & str("lname") & "</td></tr>" str.MoveNext Loop End If Response.Write("</table>") %> </form> </body> </html>

    Access database table:

    output:

    Regards,

    Jalpa.

    Friday, April 12, 2019 5:20 AM
  • User-817583793 posted

    Hello Jalpa,

    Thank you very much for taking the time to assist me; however, I don't think that is what I am looking for. I don't want to have a visitor search but instead, just return results when they click on a button.

    Example:

    [More Info]

    Will display all records that met the criteria

    Micah 968... healthy....
    Jospeh 590... healthy...

    I'm looking for a results page that browses through the database, finds specific records that meet criteria and return the results on a web page.

    Hope that makes sense. 

    Wednesday, May 1, 2019 2:54 PM
  • User-848649084 posted

    Hi,

    You could use the below code to just get data on button click.

    <html>
    <body> 
    
    
    <form method="post" name="form">
    <!--First Name: <input type="text" name="fname"><br><br />-->
    
    <input type="Submit" value="More_Info" name="btn">
    
    </form>
    <%
        btnv=Request.form("btn")
       ' Response.Write (btnv)
        If btnv = "More_Info" Then
            Dim objConn
            Set objConn = Server.CreateObject("ADODB.Connection")
            objConn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=D:\aspsamplesite\Database1.mdb;"
            objConn.Open
    
            'f_name=request.form("fname")
            'f_name=request.form("fname")
            'Response.Write (f_name)
            Set str = objConn.execute("SELECT * FROM Table1 WHERE fname='namea';")
     
            Response.Write("<table border=1>")
        Response.Write "<tr><td> fname </td><td> lname</td></tr>"
            If str.BOF And str.EOF Then
            ' No data
            Else
            Do While (Not str.EOF)
            Response.Write "<tr><td>" & str("fname") & "</td><td>" & str("lname") & "</td></tr>"
            str.MoveNext
            Loop
            End If
            
    Response.Write("</table>")
    End If
    
    %>
    </body> 
    </html>

    OR

    <html>
    <body> 
    
    
    <form method="post" name="form">
    <!--First Name: <input type="text" name="fname"><br><br />-->
    
    <input type="Submit" value="More_Info" name="btn">
    
    </form>
    <%
        btnv=Request.form("btn")
       ' Response.Write (btnv)
        select case btnv
        case "More_Info"
            Dim objConn
            Set objConn = Server.CreateObject("ADODB.Connection")
            objConn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=D:\aspsamplesite\Database1.mdb;"
            objConn.Open
    
            'f_name=request.form("fname")
            'f_name=request.form("fname")
            'Response.Write (f_name)
            Set str = objConn.execute("SELECT * FROM Table1 WHERE fname='namea';")
     
            Response.Write("<table border=1>")
        Response.Write "<tr><td> fname </td><td> lname</td></tr>"
            If str.BOF And str.EOF Then
            ' No data
            Else
            Do While (Not str.EOF)
            Response.Write "<tr><td>" & str("fname") & "</td><td>" & str("lname") & "</td></tr>"
            str.MoveNext
            Loop
            End If
            
    Response.Write("</table>")
    End Select
    
    %>
    </body> 
    </html>
    

    You could change the query string as per your requirement.

    Thursday, May 2, 2019 7:00 AM