Click here to Skip to main content
13,836,661 members
   

Database

 
PinnedHOW TO ANSWER A QUESTION PinPopular
Chris Maunder16-Jul-09 4:10
adminChris Maunder16-Jul-09 4:10 
PinnedHow to get an answer to your question PinPopular
Chris Maunder10-Nov-05 17:30
adminChris Maunder10-Nov-05 17:30 
Questionis it safe to use this with sql server and entity framework ? Pin
desanti9-Jan-19 15:38
memberdesanti9-Jan-19 15:38 
AnswerRe: is it safe to use this with sql server and entity framework ? Pin
Mycroft Holmes9-Jan-19 20:51
memberMycroft Holmes9-Jan-19 20:51 
AnswerRe: is it safe to use this with sql server and entity framework ? Pin
Eddy Vluggen10-Jan-19 3:17
mveEddy Vluggen10-Jan-19 3:17 
AnswerMessage Closed Pin
17-Jan-19 19:25
memberMember 1412184017-Jan-19 19:25 
QuestionGetting error in SQL 2012 working fine in 2016 Pin
GaneshVidiyala25-Dec-18 22:41
professionalGaneshVidiyala25-Dec-18 22:41 
AnswerRe: Getting error in SQL 2012 working fine in 2016 Pin
jschell27-Dec-18 14:34
memberjschell27-Dec-18 14:34 
Questionssrs An attempt has been made to use a data extension 'ORACLE' error Pin
anjel8425-Dec-18 21:34
memberanjel8425-Dec-18 21:34 
QuestionCan't Insert data into Access Table from Python - Solved Pin
Peter R. Fletcher5-Dec-18 16:16
memberPeter R. Fletcher5-Dec-18 16:16 
The following short Python program is supposed to read data from a SQLite datatable, convert some very large integer values in one field to Doubles, and write the data to an appropriately configured Access Table.
It runs happily with no error, but no data appears in the Access Table. What am I missing?
import sqlite3
import pyodbc

conn1 = sqlite3.connect('data.db')
cur1 = conn1.cursor()

conn2 = pyodbc.connect(r'Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=G:\My_Data_Folder\NewEnergy.accdb;')
cur2 = conn2.cursor()

data=cur2.execute('SELECT * FROM RawValues')
print (cur2.fetchall()) # this correctly displays two dummy records from the Table I am trying to fill

data=cur1.execute('SELECT * FROM RTPValues ORDER BY TimeSerial ASC')
rows=cur1.fetchall()
for row in rows:
    cur2.execute('INSERT INTO RawValues (Millitime, PowerCost) VALUES (?,?)',(float(row[0]),row[1]))
    # If I insert print statements here, they confirm that the right data is being processed
conn2.commit
conn2.close
conn1.close


[EDIT]The error, as pointed out by Richard MacCutchan at the end of the thread, is that the conn2.commit call (as well as the subsequent .close calls) are not function calls at all, because they are missing the terminal empty parentheses that are required for Python to treat them as such. The last three lines of the code should be:
conn2.commit()
conn2.close()
conn1.close()
As it stands, the program does what it is supposed to do, but the data is never written to the file.[/EDIT]

modified 8-Dec-18 14:51pm.

AnswerRe: Can't Insert data into Access Table from Python Pin
Richard MacCutchan5-Dec-18 23:19
protectorRichard MacCutchan5-Dec-18 23:19 
GeneralRe: Can't Insert data into Access Table from Python Pin
Victor Nijegorodov6-Dec-18 2:09
memberVictor Nijegorodov6-Dec-18 2:09 
GeneralRe: Can't Insert data into Access Table from Python Pin
Richard MacCutchan6-Dec-18 2:21
protectorRichard MacCutchan6-Dec-18 2:21 
GeneralRe: Can't Insert data into Access Table from Python Pin
Peter R. Fletcher6-Dec-18 3:11
memberPeter R. Fletcher6-Dec-18 3:11 
GeneralRe: Can't Insert data into Access Table from Python Pin
Richard MacCutchan6-Dec-18 4:16
protectorRichard MacCutchan6-Dec-18 4:16 
GeneralRe: Can't Insert data into Access Table from Python Pin
Peter R. Fletcher6-Dec-18 5:37
memberPeter R. Fletcher6-Dec-18 5:37 
GeneralRe: Can't Insert data into Access Table from Python Pin
Richard MacCutchan6-Dec-18 6:11
protectorRichard MacCutchan6-Dec-18 6:11 
GeneralRe: Can't Insert data into Access Table from Python Pin
Richard MacCutchan8-Dec-18 5:46
protectorRichard MacCutchan8-Dec-18 5:46 
GeneralRe: Can't Insert data into Access Table from Python Pin
Peter R. Fletcher8-Dec-18 6:04
memberPeter R. Fletcher8-Dec-18 6:04 
GeneralRe: Can't Insert data into Access Table from Python Pin
Richard MacCutchan8-Dec-18 6:58
protectorRichard MacCutchan8-Dec-18 6:58 
GeneralRe: Can't Insert data into Access Table from Python Pin
Peter R. Fletcher8-Dec-18 8:36
memberPeter R. Fletcher8-Dec-18 8:36 
GeneralRe: Can't Insert data into Access Table from Python Pin
Mycroft Holmes8-Dec-18 12:52
memberMycroft Holmes8-Dec-18 12:52 
GeneralRe: Can't Insert data into Access Table from Python Pin
Richard MacCutchan8-Dec-18 22:09
protectorRichard MacCutchan8-Dec-18 22:09 
QuestionError reading data from SQL Server ? Pin
Member 24584673-Dec-18 23:25
memberMember 24584673-Dec-18 23:25 
AnswerRe: Error reading data from SQL Server ? Pin
ZurdoDev4-Dec-18 3:22
professionalZurdoDev4-Dec-18 3:22 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.


Advertise | Privacy | Cookies | Terms of Service
Web01 | 2.8.190114.1 | Last Updated 18 Jan 2019
Copyright © CodeProject, 1999-2019
All Rights Reserved.
Layout: fixed | fluid