Jump to content
  • Advertisement
Sign in to follow this  
Stormtrooper

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

This topic is 3789 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();

            if(children)
                command.CommandText = "SELECT * FROM ViewList";
            else
                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));
                list.Add(item);
            }

            return list;
        }

System.InvalidCastException was unhandled
  Message="Specified cast is not valid."
  Source="System.Data.SQLite"
  StackTrace:
       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()
  InnerException: 

Share this post


Link to post
Share on other sites
Advertisement
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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!