473,287 Members | 1,413 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,287 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 1750
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 tblOrders where Date_Archived between #3/01/04# and...
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 about all you can imagine within the product. I...
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 access for reports and forms, etc.. I have some...
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 dynamically either through the web or from...
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 tables? 2. How does Access connect to the data in...
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, I'd like to upsize the application so I converted...
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 reference is only so helpful. The two pdf manuals are...
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 will help you judge yourself are you really worth of...
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. SQL Tuning Tips Oracle Tips Session #6 ...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
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: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...

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.