hi,
i have this code which do search in Table1 and use the result of search to search in another datatable Table2:

SqlCeConnection conne = new SqlCeConnection();
            conne.ConnectionString = @" Data source= |DataDirectory|\Database1.sdf";
            conne.Open();

            SqlCeDataReader rrs;
            SqlCeCommand comd = new SqlCeCommand("select  CodePersonne from Table1 where DateRP ='" + DateTime.Now.Date + "';", conne);
            rrs = comd.ExecuteReader();
            while  (rrs.Read())
            {
                
                SqlCeDataReader rs;
                SqlCeCommand cmd = new SqlCeCommand("SELECT [Nom],[Prenom],[DateNaissance]  FROM Table2  where CodePersonne ='" + Convert.ToInt32(rrs["CodePersonne"].ToString()) + "';", conne);
                rs = cmd.ExecuteReader();
                             
                    SqlCeDataAdapter da = new SqlCeDataAdapter(cmd);
                    DataTable dtresullt = new DataTable();
                    da.Fill(dtresullt);
                    
                    dataGridView1.DataSource = dtresullt;
            }

the problem is that code show only one row in datagridview even there are many rows in Table1 which have the condition of the first query. iwish you can help me.

The problem is that you are setting the datasource to the datagridview in a while loop and each time you loop you reset your datasource

while (rrs.Read())
{
...
DataTable dtresullt = new DataTable();
da.Fill(dtresullt);

dataGridView1.DataSource = dtresullt;
}

you need to move your datagridview outside of the while loop.


hi,
i have this code which do search in Table1 and use the result of search to search in another datatable Table2:

SqlCeConnection conne = new SqlCeConnection();
            conne.ConnectionString = @" Data source= |DataDirectory|\Database1.sdf";
            conne.Open();

            SqlCeDataReader rrs;
            SqlCeCommand comd = new SqlCeCommand("select  CodePersonne from Table1 where DateRP ='" + DateTime.Now.Date + "';", conne);
            rrs = comd.ExecuteReader();
            while  (rrs.Read())
            {
                
                SqlCeDataReader rs;
                SqlCeCommand cmd = new SqlCeCommand("SELECT [Nom],[Prenom],[DateNaissance]  FROM Table2  where CodePersonne ='" + Convert.ToInt32(rrs["CodePersonne"].ToString()) + "';", conne);
                rs = cmd.ExecuteReader();
                             
                    SqlCeDataAdapter da = new SqlCeDataAdapter(cmd);
                    DataTable dtresullt = new DataTable();
                    da.Fill(dtresullt);
                    
                    dataGridView1.DataSource = dtresullt;
            }

the problem is that code show only one row in datagridview even there are many rows in Table1 which have the condition of the first query. iwish you can help me.

yes this is the mistake, thank you so much..

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.