Click here to Skip to main content
15,893,722 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C#
private void button3_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < dataGridView1.Rows.Count; i++)
                {
                    string nn = dataGridView1.Rows[i].Cells["matricule"].Value.ToString();
                    db_connection();


                    MySqlCommand cmd = new MySqlCommand();
                    string query = "SELECT mat,dnd FROM test where mat='" + nn + "'";

                    cmd.Connection = connect;

                    DataSet ds = new DataSet();
                        
                      using (MySqlDataAdapter adapter = new MySqlDataAdapter(query, conn))
                        {
                        
                          while(adapter != null){
                              adapter.Fill(ds);


                              if (ds.Tables[0].Rows.Count != 0)
                              {

                                  DataGridViewColumn col = new DataGridViewTextBoxColumn();
                                  col.HeaderText = ds.Tables[0].ToString();
                                  int colIndex = dataGridView2.Columns.Add(col);

                                //dataGridView2.DataSource = ds.Tables[0];

                              }
                          }
                        }
                    

                }
                int count = dataGridView2.Rows.Count;
                label6.Text = count.ToString();         
        }
    }
Posted
Updated 1-Sep-15 16:46pm
v2
Comments
Suvendu Shekhar Giri 1-Sep-15 22:51pm    
What you exactly want to achieve by adding the column? What is the actual purpose?
Member 11675329 2-Sep-15 5:46am    
I have 2 datagridview '1 and 2' in the first one I select data correctly from database now I need to chek every column (of datagridview1) in another table and if got results i have to insert it into datagridview2
sreeyush sudhakaran 2-Sep-15 4:26am    
what problem you face?
Member 11675329 2-Sep-15 5:46am    
I have 2 datagridview '1 and 2' in the first one I select data correctly from database now I need to chek every column (of datagridview1) in another table and if got results i have to insert it into datagridview2
Member 11675329 2-Sep-15 5:45am    
I have 2 datagridview '1 and 2' in the first one I select data correctly from database now I need to chek every column (of datagridview1) in another table and if got results i have to insert it into datagridview2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900