title: C#: Windows Form creating table and and retrieve data from database by each dynamic button click
body: <ol>
  <li>I am trying  to develop a restaurant billing application in windows form.</li>
  <li>so I created dynamic buttons.</li>
  <li>now I need a table which will retrieve data from database for each button click.</li>
  </ol>
  
  <p>How can it possible? </p>
  
  <pre><code> private void newb_Click(object sender, EventArgs e)
   {
       Button btn = (Button)sender;
       //  textBox1.Text = btn.Text;
       connection con = new connection();
       con.connecting();
       // Button b = new Button();
       int i = 0;
       var query = "select itemname,itemcode,price from item_master                     where itemcode =" + btn.Name;
       MySqlCommand cmd = new MySqlCommand(query, con.con);
       while (i &lt; 10)
       {
  
           MySqlDataAdapter sda = new MySqlDataAdapter();
           DataTable dt = new DataTable();
           sda.SelectCommand = cmd;
           DataTable dbdataset = new DataTable();
           sda.Fill(dbdataset);
           BindingSource bsource = new BindingSource();
           bsource.DataSource = dbdataset;
  
           dataGridView1.DataSource = bsource;
        //  MessageBox.Show(btn.Name);
           i++;
       }
      // sda.Update(dbdataset);
   //  =dataGridView1.Rows[0]
  
  //// MySqlDataReader mdr;
  //// mdr = cmd.ExecuteReader();
  // while (mdr.Read()) 
  // {
  ////  textBox1.Text = (mdr["itemname"].ToString());
  // }
  }
  
   private void textBox1_TextChanged(object sender, EventArgs e)
   {
  
   }
  
   private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
   {
  
   }
  </code></pre>