ADO GetRows() example for newbies

Sam Collett sam_collett at lycos.co.uk
Fri Mar 1 12:27:09 EST 2002


How could you do pages of records (in ASP for example), you may only
want a few records at a time (if you have 1000 records for example)?
For example I may want a page with 10 records per page, with the page
numbers at the bottom.
For 100 records:
10 pages (10 links)
Start at 1 on page 1, 11 on page 2 etc)

TIA

tom at peresys.co.za (Tomasz Stochmal) wrote in message news:<f20ea932.0203010652.1045b7ff at posting.google.com>...
> #ADO GetRows() example
> 
> import win32com.client
> import pprint
> 
> def main():
>         ConnectionString = 'Provider=SQLOLEDB.1' \
>             +';Data Source=127.0.0.1' \
>             +';Initial Catalog=ZASecurities' \
>             +';User ID=sa' \
>             +';Password='
> 
>         SQL='SELECT TOP 1 * FROM TESTCASE'
> 
>         DBConnection=win32com.client.Dispatch('ADODB.Connection')        
>         DBConnection.Open(ConnectionString) 
>         try:
>             rs=win32com.client.Dispatch('ADODB.Recordset')
>             rs.Open(SQL,DBConnection)
>             try:
>                 # Info Row: Field Name/Type
>                 result=[]
>                 buf=[]
>                 for i in range(rs.Fields.Count):
>                     buf.append([rs.Fields.Item(i).Name,rs.Fields.Item(i).Type])
>     
>                 result.append(buf)
>     
>                 # Data Rows
>                 if not rs.EOF:
>                     data=rs.GetRows()
>                     assert len(data) > 0
>                     data=[[r[col] for r in data] for col in range(len(data[0]))]
>                     result.extend(data)
>             finally:
>                 rs.Close()
>     
>             pprint.pprint(result)
>         finally:
>             DBConnection.Close()
> 
> 
> if __name__ == "__main__":
>     main()
> 
> 
> # Change ConnectionString & SQL



More information about the Python-list mailing list