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())
                    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) + " " +


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 by Suzie999

1 Year
Discussion Span
Last Post 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.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.