title: Display data with ID matching text box value in datagridview?
body: <p>There is a table named <code>cartdesignsizes</code>. It has a column <code>cartkey</code>. I enter <code>cartkey</code> in a text box and I click the button and I want the entire row against that <code>cartkey</code> and I want to display that row in a datagridview.</p>
  
  <p>Here is the code:</p>
  
  <pre><code> private void btncartdesign_Click(object sender, EventArgs e)
          {
              {
                  SqlConnection sql = new SqlConnection("Data Source=75.119.176.76;Initial Catalog=virtual-11;Persist Security Info=True;User ID=sa;Password=kornit932");
                  sql.Open();
                  DataTable dt = new DataTable();
                  SqlDataAdapter sd = new SqlDataAdapter("select * from CartdesignSizes where cartkey=@txtcartkey", sql);
                  SqlCommand cmd = new SqlCommand("select * from CartdesignSizes where CartKey=@txtcartkey", sql);
                  cmd.Parameters.AddWithValue("@txtcartkey", txtcartkey.Text);
                  cmd.ExecuteNonQuery();
                  sd.Fill(dt);
                  dataGridView.DataSource = cmd.tables[0];
                  sql.Close();
                  label2.Visible = true;
                  label2.Text = dataGridView.Rows.Count.ToString();
  
              }
          }
  </code></pre>
  
  <p>Code behind the text box:</p>
  
  <pre><code>DataView DV = new DataView(dbdataset);
              DV.RowFilter=String.Format("CartKey LIKE '{0}'",txtcartkey.Text);
              dataGridView.DataSource = DV;
  </code></pre>