Click to See Complete Forum and Search --> : Simple Search


Sonia
03-04-2004, 10:43 AM
I've created a simple search using ASP. It works but the only problem is that- say a user enters a 'Roll No.' that is not found in the database, it displays the message 'DATABASE IS EMPTY' (Eventhough the db contains other records).
I tried adding an 'Else If' statement with some coding but it didn't work.
Can anyone suggest me how and where to insert the part which will display the right message if the record is not present in the database.
My coding is as follows:

<%
Dim DB
Set DB = Server.CreateObject("ADODB.Connection")
DB.ConnectionString = "DSN=StudRecord"
DB.Open

Dim RS,x
x = Request.Form("num") 'num is the name of the textbox where the user can enter the RollNo
Set RS = Server.CreateObject("ADODB.Recordset")
RS.Open "SELECT * FROM Student WHERE RollNo="& x,DB

If RS.BOF And RS.EOF Then
Response.Write "DATABASE EMPTY."

Else
RS.MoveFirst
Response.Write "Search Results<br><br>"
While Not RS.EOF
Response.Write "Roll Number:" & RS.Fields ("RollNo")
Response.Write "<br>"
Response.Write "Name: " & RS.Fields ("FirstName")
Response.Write "&nbsp;&nbsp;&nbsp;"
Response.Write RS.Fields ("LastName")
Response.Write "<br><HR color = maroon><br>"
RS.MoveNext
Wend

End If
%>

buntine
03-04-2004, 10:53 AM
Hey Sonia,

Simply alter the following line of your source code to display the correct message.

Response.Write "DATABASE EMPTY."


The .EOF and .BOF methods are used to determine whether SQL query found any records.

Regards,
Andrew Buntine.