System.Data.SQLite

Login
This project makes use of Eagle, provided by Mistachkin Systems.
Eagle: Secure Software Automation
Overview

Artifact ID: a0e52d7b75298dbee14bbbff307c91a8d09362b6
Ticket: 458738515e70f99f0ce997894c9602bfce9cb2ed
Invalid cast exception when using DataReader's GetString method on a string value that happens to be a string representation of an integer
User & Date: anonymous 2018-08-29 12:52:09
Changes

  1. icomment:
    Here's some quick code that reproduces the error (on 64-bit Windows). The directory c:\test must exist.
    
    System.Data.SQLite.SQLiteConnection SQLiteConn = new System.Data.SQLite.SQLiteConnection(@"Data Source=c:\test\test.db;Version=3;Pooling=True;Max Pool Size=100;");
                System.Data.SQLite.SQLiteCommand cmd = SQLiteConn.CreateCommand();
                SQLiteConn.Open();
                IDataReader dr = null;
                string s;
                try
                {
                    cmd.CommandText = "Create Table  test (Code String NOT NULL DEFAULT '')";
                    cmd.ExecuteNonQuery();
                    cmd.CommandText = "INSERT INTO TEST (Code) VALUES ('Test')";
                    cmd.ExecuteNonQuery();
                    cmd.CommandText = "INSERT INTO TEST (Code) VALUES ('174500')";
                    cmd.ExecuteNonQuery();
    
                    cmd.CommandText = "SELECT CODE FROM TEST";
                    dr = cmd.ExecuteReader();
                    while (dr.Read())
                    {
                        s = dr.GetString(0); //invalid cast exception here on 2nd row
                        Console.WriteLine(s);
                    }
    
                }
                finally
                {
                    dr.Close();
                    cmd.CommandText = "DROP table test";
                    cmd.ExecuteNonQuery();
                    cmd.Dispose();
                    SQLiteConn.Close();
                    SQLiteConn.Dispose();
                }
    
  2. login: "anonymous"
  3. mimetype: "text/x-fossil-plain"