Let's start from the base that this method that you show in the code is incorrect, you should NEVER build a query by concatenating the values in a string, you have to use parameters.
In addition, the code should return something if it is a SELECT, be it a list, collection or datatable with the records that you get from the select
foreach (DataGridViewRow row in dgvDispositivos.Rows)
{
string dispositivo = row.Cells[1].Value.ToString();
DataTable dt = bd.ObtenerDispositivos(dispositivo);
//resto codigo
}
public DataTable ObtenerDispositivos(string dispositivo)
{
DataTable dt = new DataTable();
using (SqlConnection conn = new SqlConnection("connection string"))
{
string query = "SELECT dispositivo,latitud,longitud FROM dispositivos WHERE dispositivo = @dispositivo";
SqlCommand cmd = new SqlCommand(query, conn);
cmd.Parameters.AddWithValue("@dispositivo", dispositivo);
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(dt);
}
return dt;
}
As you can see, the idea is to indicate the device and not the select so that we can define the query parameter