472,333 Members | 1,137 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

SQL: Exception using variables in queries

I'm getting this error when I try to insert a variable in a SQL query:

'Exception occurred.', (0, 'Microsoft JET Database Engine', 'No value given for one or more required parameters.'

Expand|Select|Wrap|Line Numbers
  1. def linker (Function):
  2.     conn = win32com.client.Dispatch(r'ADODB.Connection')
  3.     DSN = 'PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=db8.mdb';
  4.     conn.Open(DSN)
  5.     rs = win32com.client.Dispatch(r'ADODB.Recordset')
  6.     rs.Open("SELECT MAX(COID) as ID from SYS", conn)
  7.     NewID=rs.Fields("ID").Value+1
  8.     strNewID=str(NewID)
  9.     conn.Close()
  10.     sql_statement= "INSERT INTO Table1 (Comp, Fam) VALUES (" + strNewID + ", '" + Function + "')"
  11.  
  12.  
The problem is with the Function variable. When I hardcode a string it works fine, and even when I print the statement, it looks exactly as when I hardcoded it. But for some reason, it doesn't like it like that.

Any ideas?
Mar 31 '08 #1
3 1705
jlm699
314 100+
You could always try to use string formatting instead... maybe see if there's really something else going on here?
Expand|Select|Wrap|Line Numbers
  1. sql_statement= "INSERT INTO Table1 (Comp, Fam) VALUES (%s, '%s')" % (strNewID, Function)
Mar 31 '08 #2
Thanks for the suggestion. Just tried it--still the same error.
Mar 31 '08 #3
Oh wait, it worked!

Thank you!
Mar 31 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Stuart | last post by:
Hi All, Can anyone help. Q1. How do I send 2 dates to a stored query in access. What I have in the query so far is Select * from...
11
by: Bã§TãRÐ | last post by:
I have been working on this particular project for a little over 2 weeks now. This product contains between 700-900 stored procedures to handle just...
1
by: bmeyynospamnospam | last post by:
I am new to sql and very familiar with access. I am using a very large database(130M records) in ms sql2000 and think I need to front end it with...
6
by: Brad | last post by:
I have an sql query that has specific criteria (like state='PA' or state = 'NJ'...) and would like to be able to have the user specify the criteria...
42
by: PC Datasheet | last post by:
I have zero experience with using a SQL database for a backend and Access for a frontend. I have some questions: 1. Does an SQL database have...
2
by: Martin | last post by:
Hi, I currently have an application that connects to an MS ACCESS database. This application uses an OLEDB connection string for MS ACCESS. Now,...
138
by: Ian Boyd | last post by:
i've been thrown into a pit with DB2 and have to start writing things such as tables, indexes, stored procedures, triggers, etc. The online...
2
by: Jobs | last post by:
Download the JAVA , .NET and SQL Server interview with answers Download the JAVA , .NET and SQL Server interview sheet and rate yourself. This...
0
by: Medhatithi | last post by:
Hi, I have been in several ways benefiited from this site. I would like to share some sql tuning techniques(simple, but effective) with you all. ...
0
by: concettolabs | last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
0
better678
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
0
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
0
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: CD Tom | last post by:
This happens in runtime 2013 and 2016. When a report is run and then closed a toolbar shows up and the only way to get it to go away is to right...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...

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.