2014-01-15 42 views
0

我試圖搜索用戶在sqlite表中輸入的代碼,如果發現將該行添加到dataGridView。問題是我使用的代碼每次添加新行時都會清除datagrid。如何使用dataGridView中的sqlite表創建名稱

這裏是我使用

DataTable dt = new DataTable(); 

String insSQL = "select * from Produtos where codigo =" + txtCodigo.Text; 
String strConn = @"Data Source=C:\caixa.sqlite"; 

SQLiteConnection conn = new SQLiteConnection(strConn); 

SQLiteDataAdapter da = new SQLiteDataAdapter(insSQL, strConn); 
da.Fill(dt); 
dataGridViewProdutos.DataSource = dt.DefaultView; 

我試圖改變dataGridViewProdutos.datasourcedataGridViewProdutos.Rows.add(dt);他們增加了一個行,但總是空空的代碼。

+0

您是否檢查是否收回數據?爲什麼dt.DefaultView只是將其設置爲DataTable應該工作dataGridViewProdutos.DataSource = dt ;. – Bit

+0

此鏈接可能hlep http://msdn.microsoft.com/en-us/library/vstudio/fbk67b6z(v=vs.100).aspx – Bit

回答

0

我修復了它,刪除DataTable dt = new DataTable();從循環。我還將dt.DefeulView更改爲僅由dt使用的N4TKD和I m seeing no diference so I m。

也感謝鏈接,因爲我努力讓我的colums填充dataGridView空間,所以它非常有幫助。

+0

很高興它幫助....我可以在我的評論拼寫正確的幫助:) – Bit

相關問題