2012-03-04 58 views
0

我不知道如何解决这个问题。 这是一个应该在DataGrid中提供请求的数据记录的sqlite查询。 当我输入数字时,它可以工作! 但是,当我输入字母的。Sqlite错误(DataGrid)

SQLite的错误没有这样的列:例

我的代码:

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(); 

回答

1

如果您确信实例在表列出存在,它的类型是char,nvarchar的或其他的字符类型然后用这样的单引号包装TextBox.Text

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

何除此之外,请尽量在查询中使用参数。