Jump to content
  • Advertisement
Sign in to follow this  

[.net] Specified cast is not valid. [SQLite]

This topic is 3645 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm trying to get data from SQLite database, but I'm getting a Specified cast is not valid exception. Here is the table creation: CREATE TABLE ViewList (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT, parentID INTEGER, child BOOL, imageIndex INTEGER) I am 100% there is data in the table. The children arg is true.
        public List<TaskContainer> getContainerList(bool children)
            SQLiteCommand command = _connection.CreateCommand();

                command.CommandText = "SELECT * FROM ViewList";
                command.CommandText = "SELECT * FROM ViewList WHERE child=0";
            SQLiteDataReader reader = command.ExecuteReader();

            List<TaskContainer> list = new List<TaskContainer>();

            while (reader.Read())
//The line below ---------
                TaskContainer item = new TaskContainer(reader.GetString(1), reader.GetInt32(2), reader.GetInt32(0), reader.GetBoolean(3), reader.GetInt32(4));

            return list;

System.InvalidCastException was unhandled
  Message="Specified cast is not valid."
       at System.Data.SQLite.SQLiteDataReader.VerifyType(Int32 i, DbType typ)
       at System.Data.SQLite.SQLiteDataReader.GetInt32(Int32 i)
       at GED.TaskManager.getContainerList(Boolean children) in C:\Documents and Settings\ryanc\My Documents\Visual Studio 2008\Projects\GED\GED\TaskManager.cs:line 142
       at GED.frmMain.frmMain_Load(Object sender, EventArgs e) in C:\Documents and Settings\ryanc\My Documents\Visual Studio 2008\Projects\GED\GED\frmMain.cs:line 26
       at System.Windows.Forms.Form.OnLoad(EventArgs e)
       at System.Windows.Forms.Form.OnCreateControl()
       at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
       at System.Windows.Forms.Control.CreateControl()
       at System.Windows.Forms.Control.WmShowWindow(Message& m)
       at System.Windows.Forms.Control.WndProc(Message& m)
       at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
       at System.Windows.Forms.ContainerControl.WndProc(Message& m)
       at System.Windows.Forms.Form.WmShowWindow(Message& m)
       at System.Windows.Forms.Form.WndProc(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
       at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
       at System.Windows.Forms.SafeNativeMethods.ShowWindow(HandleRef hWnd, Int32 nCmdShow)
       at System.Windows.Forms.Control.SetVisibleCore(Boolean value)
       at System.Windows.Forms.Form.SetVisibleCore(Boolean value)
       at System.Windows.Forms.Control.set_Visible(Boolean value)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.Run(Form mainForm)
       at GED.Program.Main() in C:\Documents and Settings\ryanc\My Documents\Visual Studio 2008\Projects\GED\GED\Program.cs:line 18
       at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()

Share this post

Link to post
Share on other sites
Tried explicitly specifying the columns (and their order), instead of using '*' ?

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!