0

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.

2
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by basma.lm
0

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.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.