We have seen how to display data in a SQLite database from C #, both from console as using Windows Forms and basic components such as TextBox and ListView.
If we simply a "grid" similar to those of spreadsheets, which can modify and add data, there is a simple way to get it: from the visual editor added a DataGridView to our form and connect to our table SQLiteDataAdapter using a DataSet and a DataTable.
1:
private void ActualizarListaCiudades (
) 2: {
3: connection = 4 :
new SQLiteConnection 5: (
;
6:
connection. Open
(
)7:
"select * from city "
10:
11:
/ / Data Adapter, DataSet and Table 12: SQLiteDataAdapter db = new SQLiteDataAdapter (
consultation, connection )
;
13: DataSet ds = new DataSet
( ) ; 14: ds
. Reset ( ) ; 15: DataTable dt
= new DataTable
(
) ; 16: db
.
Fill (ds )
; 17: 18: / / Assign the DataTable the first table (cities) 19: / / and show it in the DataGridView 20:
dt = ds
. Tables [ 0 ] ;
21: dataGridView1.DataSource dt = ; 22: 23: / / And we can close the connection 24:
connection. Close ( ) ; 25:
}