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 9th, 2003, 05:37 AM
Authorized User
 
Join Date: Aug 2003
Posts: 78
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to spraveens
Default record set problem

Hi
     My Problem Is that when I execute the query " select * from customer where name='philip' ", and if there are no matching records then How do I display a message such as "no such records" ,please give me the code .

Thank You
Praveen...

 
Old September 9th, 2003, 06:02 AM
Authorized User
 
Join Date: Jun 2003
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi

Depends on how you execute the command....
generally
<%
'use the connection string or DSN to connect....
Dim objRS, objConn, sqlQuery, strParam
strParam = "Philip"
sqlQuery = "SELECT * FROM Customer Where Name = '" & strParam & "' "
Set objConn = Server.CreateObject("ADODB.Connection")
objConn.Open strConnString
Set objRS = objConn.Execute sqlQuery
If Not objRS.BOF AND Not objRS.EOF Then
    '....code here....
Else
   Response.Write "Sorry, no matches found for " & strParam & ".<br />"
End If
If Not objConn Is Nothing Then Set objCOnn = Nothing

If Not objRS Is Nothing Then Set objRS = Nothing

%>

 
Old September 9th, 2003, 06:41 AM
Authorized User
 
Join Date: Aug 2003
Posts: 78
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to spraveens
Default

Hello
     I modified your code to look like this :

          If Not objRS.BOF AND Not objRS.EOF Then
                     response.write "record found "
          Else
                     Response.Write "Sorry, no matches found "
          End If
but I get "record found " printed whether the given parameter exists or not.i.e. even if "philip" doesnt exist ,still i get "record found"

please help..
praveen...

 
Old September 9th, 2003, 07:05 AM
Authorized User
 
Join Date: Jun 2003
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi

Try writing out what the query thinks it has found...
using some generic code....

Dim fld

If Not objRS.BOF AND Not objRS.EOF Then
   Response.Write("<table border=""1""><tr>")
   For Each fld in objRS.Fields
     Response.Write("<td>" & fld.Name & "</td>")
   Next
   Response.Write("</tr>")
   While Not objRS.EOF
     Response.Write("<tr>")
     For Each fld in objRS.Fields
       Response.Write("<td>" & objRS.Fields(fld.Name) & "&nbsp;</td>")
     Next
     Response.Write("</tr>")
     objRS.MoveNext
   Wend
   Response.Write("</table>")
Else
    Response.Write "Sorry, no matches found "
End If


See what this produces...
Check the code spelling before trying to run!


 
Old September 9th, 2003, 07:23 AM
Authorized User
 
Join Date: Aug 2003
Posts: 78
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to spraveens
Default

here is my program :


<%
                'declare variables
                Dim Conn
                Dim Rs
                Dim filePath
                Dim mysql
                dim sqlstmt
                dim index
                dim temp
                dim temp1
                dim sqlstmt1



                 ' map the path of the database to a variable
                 filePath = Server.MapPath("serverdocket.mdb")
                'receive the parameter server name and save it to temp
                temp= trim(request.form("txtservername"))
                temp1=cdate(trim(request.form("txtdate")))
               ' create ado connection
                 Set Conn = Server.CreateObject("ADODB.Connection")
                 set rs= server.Createobject("ADODB.recordset")
                Conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & filePath
               sqlstmt1="select * from activitysoft where servername='" &temp&"' and activitydate ='"&temp1&"'"
                ' create ado recordset
on error resume next
                 Set Rs = Conn.Execute (sqlstmt1)





 %>



<center>
<br><br><br><br><br><br>


<%
'use delete statement to delete the record

  sqlstmt = "DELETE * FROM activitysoft WHERE servername='" &temp&"' and activitydate ='"&temp1&"'"
  conn.execute(sqlstmt)





%>

'now if the variables temp and temp1 do exist ,then the record is deleted , else a message "no record found" is returned.how do I do print "no record found" when there are no matching records.
thankzzz
praveen..

 
Old September 10th, 2003, 03:05 AM
Authorized User
 
Join Date: Jun 2003
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Default

..check the datatype for the 'activitydate' in the database.
If this is a date/time field then you may need to amend your sql statement to use hash characters instead of single quotes to surround the temp1 varaible value, as below.

sqlstmt1="select * from activitysoft where servername='" &temp&"' and activitydate =#"&temp1&"#"

If there are matches then go on to delete them else show a message indicating no matching records found.

Basically:
1. execute the SELECT statement to check for matching records as you
   are already doing.
2. Then check the recordset object for BOF /EOF
3. If BOF and EOF are TRUE then there are no matches
      display a message.
   Else
      there is data that matches so go on to
      execute the DELETE statement
   End If

Is this what you mean?
If so, you already have code examples of how to achieve this, just make sure that you don't close the connection until you really need to.

 
Old September 12th, 2003, 06:29 AM
Authorized User
 
Join Date: Aug 2003
Posts: 78
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to spraveens
Default

ITZ Workin !!!!!!

Thankzzzz a LOTTTTTTT

Praveen....






Similar Threads
Thread Thread Starter Forum Replies Last Post
help about record set shankhan Classic ASP Databases 1 June 5th, 2005 10:51 PM
Possible Emty Record Set englandera Classic ASP Databases 2 November 24th, 2004 01:37 PM
Inserting A Record Set nikotromus Access VBA 3 September 14th, 2004 01:23 PM
asp javascript "record set help" terry_s Classic ASP Basics 2 April 19th, 2004 07:46 AM
dynamicly name a record set mat41 Classic ASP Professional 6 March 16th, 2004 03:50 AM





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