Note that there are some explanatory texts on larger screens.

plurals
  1. POSQLiteDataAdapter Fill exception
    primarykey
    data
    text
    <p>I'm trying to use the OleDb CSV parser to load some data from a CSV file and insert it into a SQLite database, but I get an exception with the <code>OleDbAdapter.Fill</code> method and it's frustrating:</p> <blockquote> <p>An unhandled exception of type 'System.Data.ConstraintException' occurred in System.Data.dll</p> <p>Additional information: Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints.</p> </blockquote> <p>Here is the source code:</p> <pre><code>public void InsertData(String csvFileName, String tableName) { String dir = Path.GetDirectoryName(csvFileName); String name = Path.GetFileName(csvFileName); using (OleDbConnection conn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + dir + @";Extended Properties=""Text;HDR=No;FMT=Delimited""")) { conn.Open(); using (OleDbDataAdapter adapter = new OleDbDataAdapter("SELECT * FROM " + name, conn)) { QuoteDataSet ds = new QuoteDataSet(); adapter.Fill(ds, tableName); // &lt;-- Exception here InsertData(ds, tableName); // &lt;-- Inserts the data into the my SQLite db } } } class Program { static void Main(string[] args) { SQLiteDatabase target = new SQLiteDatabase(); string csvFileName = "D:\\Innovations\\Finch\\dev\\DataFeed\\YahooTagsInfo.csv"; string tableName = "Tags"; target.InsertData(csvFileName, tableName); Console.ReadKey(); } } </code></pre> <p>The "YahooTagsInfo.csv" file looks like this: </p> <pre><code>tagId,tagName,description,colName,dataType,realTime 1,s,Symbol,symbol,VARCHAR,FALSE 2,c8,After Hours Change,afterhours,DOUBLE,TRUE 3,g3,Annualized Gain,annualizedGain,DOUBLE,FALSE 4,a,Ask,ask,DOUBLE,FALSE 5,a5,Ask Size,askSize,DOUBLE,FALSE 6,a2,Average Daily Volume,avgDailyVolume,DOUBLE,FALSE 7,b,Bid,bid,DOUBLE,FALSE 8,b6,Bid Size,bidSize,DOUBLE,FALSE 9,b4,Book Value,bookValue,DOUBLE,FALSE </code></pre> <p>I've tried the following:</p> <ol> <li>Removing the first line in the CSV file so it doesn't confuse it for real data.</li> <li>Changing the TRUE/FALSE realTime flag to 1/0.</li> <li>I've tried 1 and 2 together (i.e. removed the first line and changed the flag).</li> </ol> <p>None of these things helped...</p> <p>One constraint is that the tagId is supposed to be unique. Here is what the table look like in design view:</p> <p><img src="https://i113.photobucket.com/albums/n202/ozpowermo/temp/TagsTable.jpg" alt="Tags Table"></p> <p>Can anybody help me figure out what is the problem here?</p> <p><strong>Update:</strong><br> I changed the HDR property from <code>HDR=No</code> to <code>HDR=Yes</code> and now it doesn't give me an exception:</p> <pre><code>OleDbConnection conn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + dir + @";Extended Properties=""Text;HDR=Yes;FMT=Delimited"""); </code></pre> <p>I assumed that if <code>HDR=No</code> and I removed the header (i.e. first line), then it should work... strangely it didn't work. In any case, now I'm no longer getting the exception.</p> <p>The new problem arose here: <a href="https://stackoverflow.com/questions/2711021/sqlitedataadapter-update-method-returning-0">SQLiteDataAdapter Update method returning 0</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload