title: Update GridView Based On Table Name From TextBox
body: <p>I think my question is quite straight forward.</p>
  
  <p>Assume I have a gridview, a textbox and a button control in my .aspx page. What I want to do is pasting (or typing) the "<strong>table name of my database</strong>" into the textbox, and when the button is clicked the gridview shall display all columns from the respective table name only.</p>
  
  <p>Thanks and regards</p>
  
  <p>Update:
  1. I forget to tell that I also need to allow editing, deleting and selecting command in the gridview.
  2. Thank's for all the comments, I have tried few solutions. However I found out that the most practical way is to use DataSource (allow auto generation of insert, update, delete command). So far based on my research on Google, I haven't found any tutorials that can really teach using this method comprehensively.</p>
  
  <p>My Current Code is like this:</p>
  
  <pre><code>protected void btnFind_Click(object sender, EventArgs e)
      {
  // sdsDynamic is the sql data source
  // gvDynamic is the gridview
  // txtTable is the textbox where the table name is contained           
  SqlConnection connection = new SqlConnection(myConnectionString);
          string sqlText = "SELECT * FROM " + txtTable.Text;
          sdsDynamic.SelectCommand = sqlText;
          SqlDataAdapter adapter = new SqlDataAdapter(sqlText, connection);
          adapter.SelectCommand.CommandType = CommandType.Text;
          connection.Open();
          gvDynamic.DataSource = sdsDynamic;
          gvDynamic.DataBind();
          connection.Close();
      }
  </code></pre>