Question

I'm trying to search for a code entered by the user in a sqlite table if it's found add the row to a dataGridView. the problem is that the code I'm using clears the datagrid every time I add a new row.

Here is the code I'm using

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;

I tried to change the dataGridViewProdutos.datasource to dataGridViewProdutos.Rows.add(dt); them it adds a row but always empty.

Was it helpful?

Solution

I fixed it removing the DataTable dt = new DataTable(); from the loop. I also changed the dt.DefeulView to only dt as sugested by N4TKD and Im seeing no diference so Im using it.

Also thanks for the links it was very helpfull since I was struggling to make my colums fill the dataGridView space.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top