+ Reply to Thread
Page 3 of 4 FirstFirst 1 2 3 4 LastLast
Results 21 to 30 of 34

Thread: Counting records?

  1. #21
    The Barnfather jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead's Avatar
    Join Date
    Mar 2008
    Location
    Reston, VA
    Posts
    4,547
    Blog Entries
    9
    Real Name
    Jason
    Rep Power
    22

    Same error? What line? highlight the line in your code.
    jmurrayhead
    If you agree, give me rep.
    If you like it here...throw us a few bones to help support us.


  2. #22
    The Barnfather jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead's Avatar
    Join Date
    Mar 2008
    Location
    Reston, VA
    Posts
    4,547
    Blog Entries
    9
    Real Name
    Jason
    Rep Power
    22

    Nevermind...you were actually opening the database connection three times. Comment out this line:
    Code:
    availabilityConn.open server.mappath("../db/database.mdb")
    
    jmurrayhead
    If you agree, give me rep.
    If you like it here...throw us a few bones to help support us.


  3. #23
    Contracted Slave Centurion is on a distinguished road Centurion's Avatar
    Join Date
    Dec 2008
    Posts
    533
    Rep Power
    4

    Quote Originally Posted by jmurrayhead View Post
    Nevermind...you were actually opening the database connection three times. Comment out this line:
    Code:
    availabilityConn.open server.mappath("../db/database.mdb")
    
    No J, the db connection is just opened once:

    Code:
    <%Option Explicit
    
    <!--#include virtual="adovbs.inc"-->
    
    DIM availabilitySQL, availabilityConn, availabilityRS, adUseClient
    
    set availabilityConn=Server.CreateObject("ADODB.Connection")
    availabilityConn.ConnectionString="Provider=Microsoft.Jet.OLEDB.4.0"
    availabilityConn.open server.mappath("../db/database.mdb")
    
    'query to check all the shows that are available
    availabilitySQL = "SELECT performances.performanceID, shows.showName, performances.status FROM shows INNER JOIN performances ON shows.showID = performances.showID WHERE  (((performances.status) = ""Available"")) GROUP BY performances.performanceID, shows.showName, performances.status"
    
    Set availabilityRS = Server.CreateObject("ADODB.Recordset")
    availabilityRS.Open availabilitySQL, availabilityConn
    
    
    With availabilityRS
    	.CursorLocation = adUseClient
    	MsgBox .RecordCount & " records"
    	.Close
    End With
    Set availabilityRS = Nothing   
    
    %>
    
    The connection cannot be used to perform this operation. It is either closed or invalid in this context.
    Last edited by Centurion; February 10th, 2010 at 01:17 PM.

  4. #24
    The Barnfather jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead's Avatar
    Join Date
    Mar 2008
    Location
    Reston, VA
    Posts
    4,547
    Blog Entries
    9
    Real Name
    Jason
    Rep Power
    22

    You've yet to highlight the line the error is occurring on. This will help determine the problem. However, this should work:
    Code:
    set availabilityConn=Server.CreateObject("ADODB.Connection")
    availabilityConn.Provider="Microsoft.Jet.OLEDB.4.0"
    availabilityConn.Open(Server.Mappath("../db/database.mdb"))
    
    set availabilityRS=Server.CreateObject("ADODB.recordset")
    availabilitySQL="SELECT performances.performanceID, shows.showName, performances.status FROM shows INNER JOIN performances ON shows.showID = performances.showID WHERE  (((performances.status) = ""Available""))"
    availabilityRS.Open availabilitySQL,availabilityConn
    
    if availabilityRS.Supports(adApproxPosition)=true then
      i=availabilityRS.RecordCount
      response.write("The number of records is: " & i)
    end if
    
    availabilityRS.Close
    availabilityConn.Close
    
    jmurrayhead
    If you agree, give me rep.
    If you like it here...throw us a few bones to help support us.


  5. #25
    Contracted Slave Centurion is on a distinguished road Centurion's Avatar
    Join Date
    Dec 2008
    Posts
    533
    Rep Power
    4

    sorry J, i did edit my previous post..

  6. #26
    The Barnfather jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead's Avatar
    Join Date
    Mar 2008
    Location
    Reston, VA
    Posts
    4,547
    Blog Entries
    9
    Real Name
    Jason
    Rep Power
    22

    If you'd like, you can zip up your application (including the database) and attach it here so I can run on my IIS server to test out. Or you can email me the ZIP'd file. I'll post back with my results.
    jmurrayhead
    If you agree, give me rep.
    If you like it here...throw us a few bones to help support us.


  7. #27
    Contracted Slave Centurion is on a distinguished road Centurion's Avatar
    Join Date
    Dec 2008
    Posts
    533
    Rep Power
    4

    Excellent it works but im back to square one again :S as it says: The number of records is: -1

    The guy in the link that i posted says:
    "If you need the RecordCount to be correct, then set the CursorType to something other than forward-only (e.g. adOpenKeyset or adOpenStatic)"
    But even when i try those i still get -1.

    This record count is a b**ch

  8. #28
    Contracted Slave Centurion is on a distinguished road Centurion's Avatar
    Join Date
    Dec 2008
    Posts
    533
    Rep Power
    4

    Quote Originally Posted by jmurrayhead View Post
    If you'd like, you can zip up your application (including the database) and attach it here so I can run on my IIS server to test out. Or you can email me the ZIP'd file. I'll post back with my results.
    Not sure if you got chance to check my logic? But the idea is this:

    My logic:
    1. User enters values on form.
    2. Query uses form values to build query to count the amount of records.
    3. IF DB record count is > than user selection
    4. THEN Insert records...

    Then id book those tickets with a multiple insert depending on how many tickets are requested. Quite trivial really.

    I have PM'ed you a megaupload link

  9. #29
    The Barnfather jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead's Avatar
    Join Date
    Mar 2008
    Location
    Reston, VA
    Posts
    4,547
    Blog Entries
    9
    Real Name
    Jason
    Rep Power
    22

    The following code gave me, "The number of records is: 4", and I see there are only 4 records in the database:
    Code:
    Dim cn, rs, sql, connectionString
    connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("db/database.mdb") & ";Jet OLEDB;"
    set cn = Server.CreateObject("ADODB.Connection")
    set rs = Server.CreateObject("ADODB.RecordSet")
    
    sql = "SELECT COUNT(1) As TicketCount FROM shows"
    cn.Open(connectionString)
    set rs = cn.Execute(sql)
    if Not rs.BOF And Not rs.EOF then
    	response.write("The number of records is: " & rs("TicketCount"))
    end if
    rs.Close
    cn.Close
    set cn = Nothing
    set rs = Nothing
    
    jmurrayhead
    If you agree, give me rep.
    If you like it here...throw us a few bones to help support us.


  10. #30
    Contracted Slave Centurion is on a distinguished road Centurion's Avatar
    Join Date
    Dec 2008
    Posts
    533
    Rep Power
    4

    Quote Originally Posted by jmurrayhead View Post
    The following code gave me, "The number of records is: 4", and I see there are only 4 records in the database:
    Code:
    Dim cn, rs, sql, connectionString
    connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("db/database.mdb") & ";Jet OLEDB;"
    set cn = Server.CreateObject("ADODB.Connection")
    set rs = Server.CreateObject("ADODB.RecordSet")
    
    sql = "SELECT COUNT(1) As TicketCount FROM shows"
    cn.Open(connectionString)
    set rs = cn.Execute(sql)
    if Not rs.BOF And Not rs.EOF then
    	response.write("The number of records is: " & rs("TicketCount"))
    end if
    rs.Close
    cn.Close
    set cn = Nothing
    set rs = Nothing
    
    yes you are correct!! So in future i should excute a query like you have done? and have the connection string on one line? J, you are a legend!!

+ Reply to Thread
Page 3 of 4 FirstFirst 1 2 3 4 LastLast

Similar Threads

  1. Counting a field of two columns if the values don't match in SSRS
    By kristilee in forum SQL Server Reporting Services Help
    Replies: 5
    Last Post: September 4th, 2009, 12:21 PM
  2. Adding records
    By todd2006 in forum .NET Development
    Replies: 2
    Last Post: July 21st, 2009, 11:21 PM
  3. Looping Through Records
    By BLaaaaaaaaaarche in forum ASP Development
    Replies: 3
    Last Post: July 15th, 2009, 09:42 PM
  4. Sub/Child Records
    By Flam in forum SQL Development
    Replies: 8
    Last Post: June 16th, 2009, 02:19 PM
  5. comparing records
    By javier_83 in forum Microsoft Access
    Replies: 10
    Last Post: August 7th, 2008, 02:04 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

SEO by vBSEO