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.'
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?
'Exception occurred.', (0, 'Microsoft JET Database Engine', 'No value given for one or more required parameters.'
Code:
def linker (Function):
conn = win32com.client.Dispatch(r'ADODB.Connection')
DSN = 'PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=db8.mdb';
conn.Open(DSN)
rs = win32com.client.Dispatch(r'ADODB.Recordset')
rs.Open("SELECT MAX(COID) as ID from SYS", conn)
NewID=rs.Fields("ID").Value+1
strNewID=str(NewID)
conn.Close()
sql_statement= "INSERT INTO Table1 (Comp, Fam) VALUES (" + strNewID + ", '" + Function + "')"
Any ideas?
Comment