Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何从dataGridView中的sqlite表创建具有名称的列_C#_Sqlite_System.data.sqlite - Fatal编程技术网

C# 如何从dataGridView中的sqlite表创建具有名称的列

C# 如何从dataGridView中的sqlite表创建具有名称的列,c#,sqlite,system.data.sqlite,C#,Sqlite,System.data.sqlite,我试图在sqlite表中搜索用户输入的代码(如果找到了),并将该行添加到dataGridView。问题是,每次添加新行时,我使用的代码都会清除数据网格 这是我正在使用的代码 DataTable dt = new DataTable(); String insSQL = "select * from Produtos where codigo =" + txtCodigo.Text; String strConn = @"Data Source=C:\caixa.sqlite"; SQLite

我试图在sqlite表中搜索用户输入的代码(如果找到了),并将该行添加到dataGridView。问题是,每次添加新行时,我使用的代码都会清除数据网格

这是我正在使用的代码

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.datasource更改为dataGridViewProdutos.Rows.adddt;它添加了一行,但总是空的。

我修复了删除DataTable dt=newdatatable的问题;从循环中。我还将dt.DefeulView更改为N4TKD建议的仅dt,我看不到任何差异,所以我使用了它


还感谢链接,这非常有帮助,因为我一直在努力让我的列填满dataGridView空间。

您是否检查过是否正在返回数据?为什么dt.DefaultView只是将其设置为DataTable应该工作dataGridViewProdutos.DataSource=dt;。此链接可能会被删除