datagridview and combobox in offline Mode

130 Views Asked by At

I want to display in a datagridview informations of books that he's author is selected in combobox, in offline mode.

I wrote this code to fill the combobox with ahutor's name

private void Liste_des_Livres_Load(object sender, EventArgs e)
{
           DA = new SqlDataAdapter("SELECT * FROM Livre", con);
           DA.Fill(DS, "Liv");
           for (int i = 0; i < DS.Tables["Liv"].Rows.Count; i++)
           {
               comboBox1.Items.Add(DS.Tables["Liv"].Rows[i][2]);
           }
}

and this to display the informations and there's the problem

private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            DA = new SqlDataAdapter("SELECT * FROM Livre WHERE Auteur='" + comboBox1.Text + "';", con);
            DA.Fill(DS, "liv");
            dataGridView1.DataSource = DS.Tables["liv"];
        }

in the results when I click in one item of the combobox I got all informations of all authors + again the informarions of selected author.

I tried to add dataGridView1.Rows.Clear(); but it didn't work I got an exception System.ArgumentException : 'Impossible d'effacer cette liste.'

0

There are 0 best solutions below