Wrox Programmer Forums
|
Classic ASP Databases Discuss using ASP 3 to work with data in databases, including ASP Database Setup issues from the old P2P forum on this specific subtopic. See also the book forum Beginning ASP.NET Databases for questions specific to that book. NOT for ASP.NET 1.0, 1.1, or 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Databases section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 13th, 2004, 01:14 PM
Authorized User
 
Join Date: Jul 2003
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Default Search Database

hi everyone,

I'm new to ASP. Can anyone tell me how to search database & display the results. The database consists of 3 fields->name,employeeid,place.If I enter employeeid & click on submit button in the same page it should display the results.Employeeid is unique key.The database is on remote machine I mean that database is on some computer where employee type in his ID & click on submit then it should display his name,employee id & place in a table.

thanks for all in advance.

Pradeep


 
Old September 15th, 2004, 05:47 AM
Friend of Wrox
 
Join Date: Sep 2004
Posts: 104
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to sureshbabu Send a message via Yahoo to sureshbabu
Default

---------------
Hi Please go through follwong code. If u dont understand mail be back.
Here first i am checking value in the text box. If there is any value then I am searching with that string.
Thanks
Suresh([email protected])



---------------
<%@ Language=VBScript %>
<%

If Request.Form("tEmpId") <> "" Then
    Dim objRs,objConn,cstrSql
    set objRs = server.CreateObject("ADODB.RECORDSET")
    set objConn = server.CreateObject("ADODB.CONNECTION")
    cstrSql = "select empno,ename from employee where empno=" & cint(Request.Form("tEmpId"))
    objConn.ConnectionString = "Provider=sqloledb.1;UID=sa;pwd=007;database=sampl e;DSN=user-37"
    objRs.CursorLocation = 3
    objConn.Open
    objRs.Open cstrSql,objConn,3,2

End If
%>
<HTML>
<HEAD>
<script>
function checkId(e)
{

    if(e.keyCode >= 48 && e.keyCode <=57)
    {
        return true;
    }
    else
    {
        return false;
    }
}
</script>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
</HEAD>
<BODY>
<form name=fEmp action="EmployeeSearch.asp" method=post>
<input type=text name="tEmpId" onkeyPress="return checkId(event)">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs p;&nbsp;
<input type=submit>
<%If Request.Form("tEmpId") <> "" Then%>
    <%If objRs.RecordCount > 0 Then%>
    <Table border=1>
        <TR align=center>
            <TD><b>Employee ID</b></TD><TD><b>Employee Name</b></TD>
        </TR>
        <TR align=center>
            <TD><%=objRs("empno")%></TD><TD><%=objRs("ename")%></TD>
        </TR>
    </Table>
    <%End If
    set objRs= nothing
    set objConn = nothing
    %>
<%End If%>

</form>
<P>&nbsp;</P>

</BODY>
</HTML>







Similar Threads
Thread Thread Starter Forum Replies Last Post
Search in Database????? Samora C# 2 October 10th, 2007 07:41 AM
how to search in database saif44 ASP.NET 2.0 Professional 11 March 8th, 2006 03:33 PM
need help, to Search from database vikky17 Classic ASP Basics 1 February 5th, 2006 12:35 AM
database search rajuru PHP Databases 2 November 9th, 2004 04:32 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.