mardi 21 avril 2015

SQLite in C# gives exception "database schema has changed no such column: IntFanSt"

using (SQLiteConnection con = new SQLiteConnection(connectionString))
{
    try
    {
        con.Open();
    }
    catch (Exception ex)
    {
        Console.WriteLine(ex.ToString());
    }

    if (con.State == System.Data.ConnectionState.Open)
    {
        Console.WriteLine("Database Opened");

        string selectQuery = "SELECT IntFanSt, ExtFanSt, LockSt, LightSt, IntTemperature, ExtTemperature, TargetTemperature, CpuTemperature, DoorSt, PresenceSt" +
        "FROM GET WHERE BoxNumber = @boxNumber order by GetCommandNumber desc limit 1";                                                                                         

        using (SQLiteCommand selectSQL = new SQLiteCommand(selectQuery, con))
        {
            selectSQL.Parameters.AddWithValue("@boxNumber", 13);

            using (SQLiteDataReader rdr = selectSQL.ExecuteReader())
            {
                while (rdr.Read())
                {
                    Console.WriteLine(rdr.toString());


                }
            }
        }                       
    }
}

This is how I created my database connection and assigned my selectSQL query. Than I execute this query on SQLiteDataReader object. The program prints the "Database Opened" part than gives the exception in the title.

This is the database creation statement:

CREATE TABLE `GET` (
`GetCommandNumber`  INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE,
`Time`  TEXT,
`BoxNumber` INTEGER,
`IntFanSt`  TEXT,
`ExtFanSt`  TEXT,
`LockSt`    TEXT,
`LightSt`   TEXT,
`IntTemperature`    INTEGER,
`ExtTemperature`    INTEGER,
`TargetTemperature` INTEGER,
`CpuTemperature`    INTEGER,
`DoorSt`    TEXT,
`PresenceSt`    TEXT
);

Aucun commentaire:

Enregistrer un commentaire