// Method used to retrieve last unique ID from tables private static string getLastUniqueID(string table, string uniqueId) { string lastUniqueKey = null; System.Data.DataSet dataset = new System.Data.DataSet(); if ((table != null) && (uniqueId != null)) { string queryString = "SELECT TOP 1 " + uniqueId + " FROM " + table + " ORDER BY " + uniqueId + " DESC"; try { dataset = DatabaseConnectionHandler.executeSelectQuery(queryString, null); if (dataset != null) { foreach (System.Data.DataRow row in dataset.Tables[0].Rows) { lastUniqueKey = row[uniqueId.ToUpper()].ToString(); } } } catch (Exception ex) { Console.WriteLine(ex.Message); } } return(lastUniqueKey); }