IBE.SQL.EliteDBIO.GetNeighbourSystems C# (CSharp) Method

GetNeighbourSystems() public method

gets all neighbours in a bubble around a system
public GetNeighbourSystems ( Int32 stationId, Double maxDistance ) : DataTable
stationId System.Int32 system in the center of the bubble
maxDistance Double radius of the bubble
return System.Data.DataTable
        public DataTable GetNeighbourSystems(Int32 stationId, Double maxDistance)
        {
            String sqlBaseString;
            String sqlString;
            DataTable data            = new DataTable();
            DataColumn[] keys         = new DataColumn[1]; 

            try
            {

                sqlBaseString =  " select FS.Id, FS.Systemname, sqrt(POW(FS.x - BS.x, 2) + POW(FS.y - BS.y, 2) +  POW(FS.z - BS.z, 2)) as Distance" +
                                 " from (select * from tbSystems " + 
                                 "         where id = {0}) BS" +
                                 " join tbSystems FS on (sqrt(POW(FS.x - BS.x, 2) + POW(FS.y - BS.y, 2) +  POW(FS.z - BS.z, 2)) <=  {1});";

                sqlString = String.Format(sqlBaseString, stationId, maxDistance);

                Program.DBCon.Execute(sqlString, data);

                keys[0] = data.Columns["Id"];
                data.PrimaryKey  = keys;

                return data;

	        }
	        catch (Exception ex)
	        {
		        throw new Exception("Error while getting neighbours of a system", ex);
	        }
        }