title: Clearing datagridview with datasource
body: <p>My application has an datagridview that displays data via mysql connector, i want to clear or refresh the datagrid, but can't figure out how.</p>
  
  <p>I tried </p>
  
  <pre><code>dataGridView2.DataSource = null; 
  </code></pre>
  
  <p>but it won't clear the data source.</p>
  
  <p>This is my code</p>
  
  <pre><code>using MySql.Data.MySqlClient; 
  
  Boolean DataLoaded = false;
      string SQL = null;
  
      MySqlConnection MysqlConn;
      MySqlCommand WerkDataCommand = new MySqlCommand();
      MySqlDataAdapter WerkDataAdapter = new MySqlDataAdapter();
      DataTable WerkData = new DataTable();
  
  private void gegevensOphalenBTN_Click(object sender, EventArgs e)
      {
          MysqlConn = new MySqlConnection();
  
          MysqlConn.ConnectionString = "server=myserver;" + "user id=user;" + "password=***;" + "database=database";
  
          SQL = "SELECT * FROM werkverslagen";
  
  
          try
          {
              dataGridView2.DataSource = null;
              MysqlConn.Open();
  
              WerkDataCommand.Connection = MysqlConn;
              WerkDataCommand.CommandText = SQL; 
  
              WerkDataAdapter.SelectCommand = WerkDataCommand;
              WerkDataAdapter.Fill(WerkData);
  
              dataGridView2.DataSource = WerkData;
          }
          catch (MySqlException myerror)
          {
              MessageBox.Show("Database gives the following error: " + myerror.Message);
          }
          finally
          {
              MysqlConn.Close();
              MysqlConn.Dispose();
              button4.Enabled = true;
          }
      }
  </code></pre>
  
  <p>It will still keep the datasource and adds the same rows to the grid.</p>