title: Elegant way to insert list into odbc row using pyodbc
body: <p>I'm just getting into python and SQL. I'm able to connect to my db, and query from it. Now I'd like to insert rows. In particular, I have a dictionary of lists. I'd like to insert each list into the database as part of a row. Since my lists are long, I'd like to find an elegant way to do it.</p>
  
  <p>The table is given by the definition:</p>
  
  <pre><code>CREATE TABLE [dbo].[ExampleTable](
      [ID] [int] IDENTITY(1,1) NOT NULL,
      [Date] [date] NOT NULL,
      [Name] [nvarchar](50) NOT NULL,
      [columnA] [nvarchar](50) NULL,
      [columnB] [int] NOT NULL,
      [columnC] [decimal](5, 4) NOT NULL,
      [columnD] [int] NOT NULL
      ...
      [columnX] [nvarchar](50) NOT NULL
  )
  </code></pre>
  
  <p>So far I have:</p>
  
  <pre><code>import pyodbc
  import datetime
  import time
  
  cnxn = pyodbc.connect(connStr)
  db_cursor = cnxn.cursor()
  
  myDict = dict()
  myDict['key1'] = ['John Doe', 5, 0.978, -1, ..., 'x'] # there are many columns here
  thisDate =  datetime.date(2014, 10, 22)
  myTable = ExampleTable
  
  insertQuery  = "insert into %s value(?, ?, ?)" %myTable
  
  
  for key in myDict:
      db_cursor.execute(insertQuery, key, thisDate.strftime('%Y-%m-%d'), myDict[key])
      cnxn.commit()
  </code></pre>
  
  <p>Here I get an error:</p>
  
  <blockquote>
    <p>ProgrammingError: ('Invalid parameter type.  param-index=4
    param-type=list', 'HY105')</p>
  </blockquote>
  
  <p>Is there a way to do this elegantly, without having to reference each element in the dictionary's lists?</p>
  
  <p>Thanks!</p>