title: Writing a csv file into SQL Server database using python
body: <p>I am trying to write a csv file into a table in SQL Server database using python. I am facing errors when I pass the parameters , but I don't face any error when I do it manually. Here is the code I am executing.</p>
  <pre><code>cur=cnxn.cursor() # Get the cursor
  csv_data = csv.reader(file(Samplefile.csv')) # Read the csv
  for rows in csv_data: # Iterate through csv
      cur.execute(&quot;INSERT INTO MyTable(Col1,Col2,Col3,Col4) VALUES (?,?,?,?)&quot;,rows)
  cnxn.commit()
  </code></pre>
  <p>Error:</p>
  <blockquote>
  <p>pyodbc.DataError: ('22001', '[22001] [Microsoft][ODBC SQL Server Driver][SQL Server]String or binary data would be truncated. (8152) (SQLExecDirectW); [01000] [Microsoft][ODBC SQL Server Driver][SQL Server]The statement has been terminated. (3621)')</p>
  </blockquote>
  <p>However when I insert the values manually. It works fine</p>
  <pre><code>cur.execute(&quot;INSERT INTO MyTable(Col1,Col2,Col3,Col4) VALUES (?,?,?,?)&quot;,'A','B','C','D')
  </code></pre>
  <p>I have ensured that the TABLE is there in the database, data types are consistent with the data I am passing. Connection and cursor are also correct. The data type of rows is &quot;list&quot;</p>