user1248067
user1248067

Reputation: 115

Sqlite error (DataGrid)

I do not know how to fix the Problem. It's a sqlite query that should give the requested data record in the DataGrid. When I enter numbers, it works! But not when i enter letter's.

SQLite error no such column: Example

My Code :

SQLiteConnection connection = new SQLiteConnection();
                connection = new SQLiteConnection("Data Source=Database.s3db;Version=3;New=False;Compress=True;");
                SQLiteCommand command = new SQLiteCommand(connection);
                SQLiteDataAdapter DB;
                DataSet DS = new DataSet();
                DataTable DT = new DataTable();
                connection.Open();

                command = connection.CreateCommand();
                string CommandText = "select Example from Lists where Example =" + textBox.Text ;
                DB = new SQLiteDataAdapter(CommandText, connection);
                DS.Reset();
                DB.Fill(DS);
                DT = DS.Tables[0];
                Grid.DataSource = DT;
                connection.Close();

Upvotes: 0

Views: 450

Answers (1)

Steve
Steve

Reputation: 216293

If you are sure that Example exist in your table Lists and its type is of char, nvarchar or other character type then wrap your TextBox.Text in single quote like this

select Example from Lists where Example ='" + textBox.Text +"'" ; 

However, try always to use parameter in your query.

Upvotes: 1

Related Questions