hi,
i work on a csharp application with sql server ce database and i have this code:

private void recherchebtn_Click(object sender, EventArgs e)
        {

            SqlCeConnection con = new SqlCeConnection();
            con.ConnectionString = @" Data source= `|DataDirectory|\Database1.sdf";
            try
            {
                con.Open();
            }
            catch (Exception ex)
            {
                MessageBox.Show("connection failed");
            }
            finally
            {

                SqlCeDataReader rs;
                SqlCeCommand cmd = new SqlCeCommand("SELECT * FROM          Condamne where Nom='" + nomTextBox.Text + "'and Prenom='" + prenomTextBox.Text + "'", con);
                rs = cmd.ExecuteReader();
                SqlCeDataAdapter da = new SqlCeDataAdapter(cmd);
                da.Fill(database1DataSet);
                con.Close();
                dataGridView1.DataSource = database1DataSet.Condamne;
            }
}

but this code doesn't work and nothing displayed in the datagridview.
i hope you help me and thanks..

hi,
thanks for replay. yes,i use the data source that i have created before ( database1Dataset).

hi,
i find the solution. i made a mistake and forgot to use datatable, so the correct code is:

private void recherchebtn_Click(object sender, EventArgs e)
        {

            SqlCeConnection con = new SqlCeConnection();
            con.ConnectionString = @" Data source= D:\messaouda\logicielcasier22\logicielcasier\Database1.sdf";
            try
            {
                con.Open();
            }
            catch (Exception ex)
            {
                MessageBox.Show("connection failed");
            }
            finally
            {
                 SqlCeDataReader rs;
                SqlCeCommand cmd = new SqlCeCommand("SELECT [Nom],[Prenom],[DateNaissance],[AnneeJugee],[NomPere],[NomPrenomMere],[SituationFamiliale] FROM Condamne where Nom='" + nomTextBox.Text + "'and Prenom='" + prenomTextBox.Text + "'", con);
                    SqlCeDataAdapter da = new SqlCeDataAdapter(cmd);
                    DataTable dtresullt = new DataTable();
                    da.Fill(dtresullt);
                    dataGridView1.DataSource = dtresullt;
            }
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.