Hey there.. after days of trying to solve this problem by trying some variations of my code, I'm desperate.
I'm trying to fill my DataGridView with SQLite database - it works.. but.. DatGridView shows me only a few rows, for whatever reason.
additional info:
SQLite queries work perfectly (tried in "DB Browser in SQLite")
also tried UNION/UNION ALL and cmd.ExecuteReader/cmd.ExecuteNonQuery + cmd.ExecuteReader
code:
- private void button1_Click(object sender, EventArgs e)
- {
- SQLiteConnection myconnection = new SQLiteConnection("Data Source=C:\\Users\\jprochazka\\Desktop\\HG DB SQLite\\hg_db07 - serverside\\hg_db06\\databaze_heinz_glas.db;Version=3");
- myconnection.Open();
- SQLiteCommand cmd = new SQLiteCommand();
- cmd.Connection = myconnection;
- cmd.CommandText = "SELECT id, nazev_tabulky, nazev_zarizeni, typ_zarizeni, vyrobce, umisteni, evidencni_cislo FROM Spotrebice UNION " +
- "SELECT id, nazev_tabulky, nazev_zarizeni, typ_zarizeni, vyrobce, umisteni, evidencni_cislo FROM Stroje UNION " +
- "SELECT id, nazev_tabulky, prurez, typ_kabelu, vyrobce, umisteni, evidencni_cislo FROM Prodluzovaci_Privody UNION " +
- "SELECT id, nazev_tabulky, nazev, oznaceni, vnejsi_vlivy, null, ev_c FROM Prostory UNION " +
- "SELECT id, nazev_tabulky, oznaceni, typ_zarizeni, vyrobce, umisteni, vyrobni_cislo FROM Rozvadece;";
- using (SQLiteDataReader sdr = cmd.ExecuteReader())
- {
- DataTable dt = new DataTable();
- dt.Load(sdr);
- sdr.Close();
- myconnection.Close();
- dataGridView1.DataSource = dt;
- }
- }
Thanks for every advice.
Rajanikant HawaldarPosted Dec 6, 2020, 11:33 PM
Zrnko KávyPosted Dec 6, 2020, 11:59 PM
Zrnko KávyPosted Dec 6, 2020, 11:55 PM
Sachin SinghPosted Dec 6, 2020, 11:35 PM
Basic rules for combining two or more queries using UNION :
1.) number of columns and order of columns of all queries must be same.
2.) the data types of the columns on involving table in each query must be same or compatible.