I'm reading data from SQLite database table.
If the SQLiteDataReader encounters a negative double an InvalidCastException is thrown.

Here is my code.

public void DBToArray()
        {
            string stm = "SELECT * FROM mtable";

            SQLiteCommand cmd = new SQLiteCommand(stm, sqlcon);

            SQLiteDataReader rdr = cmd.ExecuteReader();

            while (rdr.Read())
            {
                Console.WriteLine(
                    rdr.GetInt32(0) + " " +
                    rdr.GetString(1) + " " +
                    rdr.GetString(2) + " " +
                    rdr.GetString(3) + " " +
                    rdr.GetInt32(4) + " " +
                    rdr.GetDouble(5) + " " + /* -5.0 no good */
                    rdr.GetString(6) + " " +
                    rdr.GetString(7)
                    );
            }


        }

Just wondering if anyone has encountered and solved this issue?

I could make that particular double column a string and cast it later with Convert.ToDouble but I'd sooner not if there is another solution.

I cannot find any information on System.Data.SQLite having a problem with negative double.

Thanks for looking.

Edited 1 Year Ago by Suzie999

The code above is fine, it was user error.

I'm very sorry if I've wasted anyone's time.

It was just a coincidence that I had another problem in the rows in which negative values are stored.

A default string was entered into column(0) when a value was not found during table creation.

Sorry for any inconvenience.

This question has already been answered. Start a new discussion instead.