473,320 Members | 2,122 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Python help for Access database

HI All,

I need help for inserting recods into the access database using python
script through ODBC. I can insert data without any problem if I hard
coded the run_Date field. But I need run_Date field should be mytime..
I am getting error Data type mismatch in criteria expression. in EXEC

I really appreciate if anyone can help me.

Thanks in advance

Shakir

# mdbupdate.py

import sys
import os
import os.path
import shutil
import time
import sys, string, os, win32com.client
import odbc
mytime = time.strftime('%m/%d/%Y')
mytimeYMD = time.strftime('%Y%m%d')
conn = odbc.odbc("test1_Data")
cursor = conn.cursor()

# data type in mdb is as follows: application -Text, Run_Date ->
Date, Run_dateYMD -#number, status -Script

cursor.execute("INSERT INTO local_cmgenadm (Application,Run_Date,
Run_DateYMD,status) values (\'MyApp1\',\'%s\', \'20060731\' ,
\'Good\')")%mytime

cursor.close()

conn.close()

Jul 31 '06 #1
3 1812

shakir wrote:
HI All,

I need help for inserting recods into the access database using python
script through ODBC. I can insert data without any problem if I hard
coded the run_Date field. But I need run_Date field should be mytime..
I am getting error Data type mismatch in criteria expression. in EXEC

I really appreciate if anyone can help me.

Thanks in advance

Shakir

# mdbupdate.py

import sys
import os
import os.path
import shutil
import time
import sys, string, os, win32com.client
import odbc
mytime = time.strftime('%m/%d/%Y')
mytimeYMD = time.strftime('%Y%m%d')
conn = odbc.odbc("test1_Data")
cursor = conn.cursor()

# data type in mdb is as follows: application -Text, Run_Date ->
Date, Run_dateYMD -#number, status -Script

cursor.execute("INSERT INTO local_cmgenadm (Application,Run_Date,
Run_DateYMD,status) values (\'MyApp1\',\'%s\', \'20060731\' ,
\'Good\')")%mytime
1. Why do you think you need all those \ characters?

2. Try this elementary debugging procedure:

sql = "INSERT ......."
print sql
print mytime
print sql % mytime
# compare the result with your hard-coded effort
cursor.execute(sql)

3. You may wish to try the parameterised approach:

cursor.execute("insert ... values (?,?,?,?)", ( 'MyApp1',mytime,
'20060731' ,'Good'))

[google "SQL injection attack"]

4. You may wish to try another interface: adodbapi [I've used that OK
but the project seems dormant (last update 3 years ago)] or mxODBC
[very good but not free].
If you are not constrained to use MS Access, consider sqlite3.

Cheers,
John

Jul 31 '06 #2
John Machin wrote:
>or mxODBC
[very good but not free].
I love mxODBC. It's free for noncommercial use.

http://www.egenix.com/files/python/mxODBC.html

rd

Jul 31 '06 #3

BartlebyScrivener wrote:
John Machin wrote:
or mxODBC
[very good but not free].

I love mxODBC. It's free for noncommercial use.
I was presuming that the OP was mucking about with Access only because
he was so constrained by his job :-)

Jul 31 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: David ROBERT | last post by:
Hello, I need to read data from a MS Access database. The program (reader) is installed on a linux box and is written in python langage. The database is MS Access 2002 installed on a Win XP box...
9
by: DD | last post by:
Hello, Could anyone please help me?? Is there somebody who could explain me how to make a connection to a access database with a python cgi script. I would like to use common sql commands in my...
1
by: Uggen Kristin T | last post by:
For the first time, I am trying to program python in a windows-environment, and now I am having some trouble with combining python and MS Access... This is what I want to do: A MS Access...
2
by: aum | last post by:
Hi, I'm looking for an object-relational layer, which can wrap a MySQL database into highly pythonic objects. There seem to be dozens of packages which provide some of this functionality, but...
0
by: asdf sdf | last post by:
wondering what python resources might be available for python-based legacy system access, particularly to MVS, DB2 and Adabas. What additional pieces might be needed to implement this access? ...
1
by: bill ramsay | last post by:
Dear all. I am using an existing hodge-podge of an application that runs on top of an Access database. This application dials up customer equipment, handshakes then downloads/uploads various...
4
by: Carl | last post by:
Using COM and ADO on Win32, it is very easy to access databases (eg MySql, MS SQL Server, etc) from Python. Does anybody know if it is possible to access databases from Zope (which is written in...
10
by: Andrew Dalke | last post by:
Is there an author index for the new version of the Python cookbook? As a contributor I got my comp version delivered today and my ego wanted some gratification. I couldn't find my entries. ...
31
by: stéphane bard | last post by:
hello, my boss ask me to prefer windev to python. I have to argue - python work on multiple platform (linux, mac, windows) A good point but it didn't interest him. Because we want to choose a...
0
by: M.-A. Lemburg | last post by:
On 2008-05-12 07:43, Banibrata Dutta wrote: Most Python database modules adhere to the Python Database API specification (DB-API). The current version 2 is available in the PEP format as: ...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.