The accepted answer solves your problem, however queries with chain concatenation are not recommended.
It is advisable to use parameterized queries instead of concatenating the strings. It would be something like this:
Creating a variable in the query: @nombre_variable
.
"SELECT * FROM TCTERCEROS WHERE TR_TERCERO LIKE @nombre_variable";
And the way to use it would be something like this:
comando.Parameters.Add("@nombre_variable", suTipoDato).Value = "%" + TBNit.Text + "%";
With this, avoid the SQL injection ...
Just to give a larger example:
using(SqlConnection con = new SqlConnection(...))
{
string Comando = "SELECT * FROM TCTERCEROS WHERE TR_TERCERO LIKE @nombre_variable";
using (SqlCommand cmnd = new SqlCommand(Comando, con)
{
cmnd.CommandType = CommandType.Text;
cmnd.Parameters.Add(new SqlParameter() {
ParameterName = "@nombre_variable",
SqlDbType = SqlDbType.NVarChar,
Value = string.Format("%{0}%", TBNit.Text)
});
con.Open();
using (SqlDataReader dataReader = cmnd.ExecuteReader())
{
DataTable dt = new DataTable();
SqlDataAdapter da = new SqlDataAdapter(consulta);
dataReader.Dispose();
da.Fill(dt);
dtgv.DataSource = dt;
}
}
}