By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,621 Members | 1,077 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,621 IT Pros & Developers. It's quick & easy.

ADO with Python

P: n/a
Is their anybody with xperience in using the both and can provide me with
some xamples.

Thx a lot
Ralf
Oct 16 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
hg
Ralf wrote:
Is their anybody with xperience in using the both and can provide me with
some xamples.

Thx a lot
Ralf

I suggest you buy the book from Mark Hammond

hg
ex (major cut and paste):

#************************************************* *******************
def Get_User_Info_From_DB(self, p_user_id):
try:
#l_query = 'Select Groups.GR_AccessDate from Groups,Members
where Members.GroupId = Groups.GR_GroupId and Members.MemberId = %s;' %
p_user_id
l_query = 'SELECT
Firstname,Lastname,GR_ExpirationDate,GR_AccessDate ,GR_CurrentBal,MemberType,MemberDues
FROM MemberTypes,Members,Groups Where (Groups.GR_GroupId =
Members.GroupId) and (MemberTypes.MemberTypeID =
Groups.GR_MembershipType) and (MemberId = %s);' % p_user_id
l_conn = win32com.client.Dispatch(r'ADODB.Connection')
l_DSN = 'PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA
SOURCE='+self.__m_database + ';'
l_conn.Open(l_DSN)
l_recordset = win32com.client.Dispatch(r'ADODB.Recordset')
l_recordset.Open(l_query, l_conn, 1, 3)
l_found_date = False
try:
l_recordset.MoveFirst()
l_exp_date =
l_recordset.Fields.Item('GR_ExpirationDate').Value
l_access_date =
l_recordset.Fields.Item('GR_AccessDate').Value

l_last_name = l_recordset.Fields.Item('Lastname').Value
l_first_name = l_recordset.Fields.Item('Firstname').Value
l_membership_type =
l_recordset.Fields.Item('MemberType').Value
#print 'HERE ', l_recordset.Fields.Item('MemberType').Value
l_val = l_recordset.Fields.Item('MemberDues').Value

l_dues_amount = '%.02f' % (float(l_val[1])/10000.0)
if None == l_access_date:
self.__m_log.Log( ('DATE IS NOT AVAILABLE FOR USER
ID %s' % p_user_id) )
else:
l_found_date = True
self.__m_log.Log( ('FOUND NEW DATE IN DATABASE FOR
USER ID %s: %s' % (p_user_id, l_access_date)) )
except:
self.__m_log.Log( ( 'GET DATE QUERY FAILED ON USER ID
%s' % p_user_id) )
self.__m_log.Log(traceback.format_exc())
l_conn.Close()

if False == l_found_date:
return None

#print 'IN GET: ACCESS ', l_access_date.Format()
#print 'IN GET: EXP', l_exp_date.Format()
return ( l_exp_date.Format(),l_access_date.Format(),
l_last_name, l_first_name, l_membership_type, l_dues_amount)
except:
self.__m_log.Log(traceback.format_exc())
try:
l_conn.Close()
except:
self.__m_log.Log('Could not close database connection on
retrieval')
self.__m_log.Log(traceback.format_exc())
pass
self.__m_log.Log( ('Fatal error retrieving date from
database for user id %s ' % p_user_id))
return None
Oct 16 '06 #2

P: n/a
Ralf wrote:
Is their anybody with xperience in using the both and can provide me with
some xamples.
Googling for python ado returns this simple tutorial
http://www.markcarter.me.uk/computing/python/ado.html

COM access in Python is straight forward with win32all.

Oct 16 '06 #3

P: n/a

Ralf wrote:
Is their anybody with xperience in using the both and can provide me with
some xamples.

Thx a lot
Ralf
I found the tutorial on this site helpful.

http://www.mayukhbose.com/python/ado/index.php

Oct 17 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.