You can try this code. Do reply by commenting if any problem occurs. Make sure to use the namespaces in your class that handles data operations. Use appropriate table and database name instead of "test" and "master" in SQL Select query and in Fill method of data adapter. Put this method in your class. And invoke it from your form.cs
using System.Data;
using System.Data.SqlClient;
DataSet getDataSet(string Command, string Connection)
{
SqlDataAdapter sda = new SqlDataAdapter(Command, Connection);
DataSet ds = new DataSet();
sda.Fill(ds, "test");
return ds;
}
private void BGetData_Click(object sender, EventArgs e)
{
dataGridView1.DataSource = getDataSet("SELECT * FROM test WHERE Name='" + TBName.Text + "'", @"Server=.\SQLEXPRESS; Database=master; Integrated Security=true;").Tables["test"];
}