display a message or redirect if the recordset is empty
if you use a filter criterium that makes it possible that no records are retrieved you should always put a "Hide Region (If Empty)" or a "Repeat Region" behaviour around the display of the database content. otherwise you might get an error "Either EOF is true or BOF..." with these behaviours the page simply displays nothing if the recordset is empty. but sometimes you might want to display a message if the recordset is empty
here is one way of how to do it with VBScript: NOTE: what you have to enter manually is only the bold part! The rest can be done using the standard tools. a hide region (if empty) code generated with the Ultradev databindings and server behaviours would look like the following: <% If Not Recordset1.EOF Or Not Recordset1.BOF
Then %> all you have to do is to enter two additional lines: <% If Not Recordset1.EOF Or Not Recordset1.BOF
Then %>
a repeat region generated with the Ultradev tools would look like the following:
<% <%=(Recordset1.Fields.Item("myField").Value)%>
an easy way to display the message is to add some new script after that so that the overal script would look like: <% <%=(Recordset1.Fields.Item("myField").Value)%>
you could use this method also in conjunction with the "HideRegion" behaviour. if you rather redirect the user to another page then use code like the following: <% |
here is the same for JavaScript: AGAIN: what you have to enter manually is only the bold part! The rest can be done using the standard tools. hide region (if empty): <% if (!Recordset1.EOF || !Recordset1.BOF){
%> repeat region: <% <%=(Recordset1.Fields.Item("myField").Value)%>
<% if (Recordset1.EOF || Recordset1.BOF)
{ |
or for redirecting <% if (Recordset1.EOF || Recordset1.BOF)
{ |