Input array is longer than the number of columns in this table
I've recently started to use SQLite and began to integrate it into a C# project I'm working on.
However, randomly my project will throw the exception:
Input array is longer than the numbe开发者_如何学Gor of columns in this table
I'm having a hard time trying the trace the problem because it seems to be thrown on a random basis.
DataTable table = new DataTable();
//exception is thrown here
table = Global.db.ExecuteQuery("SELECT * FROM vm_manager");
Some of the data that gets returned from this query is as follows:
http://i.stack.imgur.com/9rlLN.png
If anyone has any advice, I'd be grateful.
EDIT: I'm unable to show the execute query function as it resides inside a dll from the following sql lite wrapper http://www.codeproject.com/KB/database/cs_sqlitewrapper.aspx
EDIT 2 Problem stems from the new record array function inside this particular sql lite wrapper.
Based on your SQLite wrapper's implementation, it is adding columns to its own internal DataTable before returning to yours. I suspect your defect is in the wrapper, and not in your code. I dug into the source of your SQLiteWrapper from CodeProject; here it is at PasteBin: http://pastebin.com/AjGaX0kL
I suspect the error is occurring in that helper method ExecuteQuery()
, or its helpers: ReadFirstRow()
or ReadFirstRow()
, and not your code. Wrap your code in a try catch
. Inspect the Exception
, and the properties will tell you which method this exception is actually being created in.
Likely you're encountering a defect in this wrapper class.
try
{
DataTable table = Global.db.ExecuteQuery("SELECT * FROM vm_manager");
}
catch (Exception ex){
//who threw this from which method and line?
}
If this SQLite provider isn't working, suggest evaluating:
- System.Data.SQLite - An open source ADO.NET provider for the SQLite database engine
- ADO.NET 2.0 Provider for SQLite at SourceForge -- and here's a nice tutorial by Mike Duncan on this SQLite provider.
精彩评论