Sunday, 15 June 2014

database - Fill DataGridView from SQLite DB (C#) -


I am trying to fill the datagrid view with a SQLite database.

Although I have many ways to do this, I already have columns present in DGV (item, quantity).

Currently, when I load db to dgv, So I get columns of DB inserted in DGV instead of the actual data being inserted in the right column.

My SQLite DB

How to load DB in pre-existing columns of DG?

Current code for filling DGV:

  Private Zero Button 1_Click_1 (Object Sender, EventErgus E) { Set connection (); Sqlconnection.Open (); Sqlcmd = sqlconnection.CreateCommand (); Command text = "SELECT * table1"; Sqlda = New SQLiteDataAdapter (command text, sqlconnection); (Dt = new DataTable ()) using {sqlda.Fill (dt); DataGridView1.DataSource = dt; }  

If you do not want to disturb columns, then read the rows together You can place it on the DataGrid view by using SQLiteDataReader.

  Private Zero Button 1_Click_1 (Object Sender, EventErgus E) {conn.Open (); SQLiteCommand comm = New SQLiteCommand ("Choose from patients", conn); (SQLiteDataReader read = comm.ExecuteReader ()) {while (read.Read ()) {dataGridView1.Rows.Add (new object [] {read.GetValue (0), // U can read column index GETValue (Read Read the "GateOrdinal" ("PatientName" }}}  

No comments:

Post a Comment