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 " "
Response.Write RS.Fields ("LastName")
Response.Write "<br><HR color = maroon><br>"
RS.MoveNext
Wend
End If
%>
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 " "
Response.Write RS.Fields ("LastName")
Response.Write "<br><HR color = maroon><br>"
RS.MoveNext
Wend
End If
%>