Subject: "Single-Record" Recordset
Posted By: Wyatt70 Post Date: 11/18/2003 11:40:40 AM
My ASP page calls a stored procedure that returns a recordset.  Sometimes, the recordset consists only of a single record.  In this situation, I cannot get the record to display.  The page works fine when there are no records or when there are multiple records.  I need to design an IF-THEN-ELSE statement to handle each of these situations, but I cannot figure out how to specify the condition where there is only one record.  Can anyone help me?

Thanks in advance.
Reply By: planoie Reply Date: 11/18/2003 11:45:43 AM
If your code is set up right you shouldn't have this problem.

Can you post the code where you deal with the recordset?

Peter
------------------------------------------------------
Work smarter, not harder.
Reply By: Wyatt70 Reply Date: 11/18/2003 12:20:27 PM
Here you go:

<%
  Dim strConnect
%>
<!-- #include file="ConnectDBI_MONF06925DB.asp" -->
<!-- #include file="adovbs.inc" -->
<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
<TITLE></TITLE>
</HEAD>
<BODY>
<%
    Dim strDatabaseName, objComm
    strServerName = Request.Form("ServerName")

    Set objComm = Server.CreateObject("ADODB.Command")
    
    objComm.ActiveConnection = strConnect
    objComm.CommandText = "ap_RemoteDBName" 'Here's where you specify the stored procedure
    objComm.CommandType = adCmdStoredProc
  
    objComm.Parameters.Append objComm.CreateParameter("@ServerName", adVarChar, _
        adParamInput, 50, strServerName)

    Set objRS = objComm.Execute
    
    If objRS.BOF and objRS.EOF then
      Response.Write strServerName & " holds the following database:<br><br>"
      Response.Write "<table border=1>"
      Response.Write "<tr><td><b>Database Name</b></td></tr>"
      strDatabaseName = objRS("DataBase_Name")
      Response.Write "<tr><td>" & strDatabaseName & "</td></tr>"
      Response.Write "</table>"
    ElseIf objRS.BOF and not objRS.EOF then
      Response.Write strServerName & " holds the following databases:<br><br>"
      Response.Write "<table border=1>"
      Response.Write "<tr><td><b>Database Name</b></td></tr>"
      objRS.MoveFirst
      While Not objRS.EOF
        strDatabaseName = objRS("DataBase_Name")
        Response.Write "<tr><td>" & strDatabaseName & "</td></tr>"
        objRS.MoveNext
      Wend
      Response.Write "</table>"
    Else
      Response.Write strServerName & " contains no databases."    
    End If
    objRS.Close
    Set objRS=Nothing
    Set objComm=Nothing
%>
</BODY>
</HTML>

Go to topic 6643

Return to index page 1002
Return to index page 1001
Return to index page 1000
Return to index page 999
Return to index page 998
Return to index page 997
Return to index page 996
Return to index page 995
Return to index page 994
Return to index page 993