public static object GetMaxFieldValue(MySqlConnection MyConnection, string TableName, string FieldName) { try { string StrMaxRequest = "SELECT MAX(" + FieldName + ") FROM " + TableName; MySqlCommand Command = new MySqlCommand(StrMaxRequest, MyConnection); return(DataBaseAccesUtilities.ScalarRequest(Command)); } catch (MySqlException e) { throw new Exception("Query Execution Error", e); } finally { MyConnection.Close(); } }
public static bool CheckFieldValueExistence(string TableName, string FieldName, MySqlDbType FieldType, object FieldValue, MySqlConnection MyConnection) { try { string StrRequest = "SELECT COUNT(" + FieldName + ") FROM " + TableName + " WHERE ((" + FieldName + " = @" + FieldName + ")"; StrRequest += "OR ( (@" + (FieldName + 1).ToString() + " IS NULL)AND (" + FieldName + " IS NULL)))"; MySqlCommand Command = new MySqlCommand(StrRequest, MyConnection); Command.Parameters.Add("@" + FieldName, FieldType).Value = FieldValue; Command.Parameters.Add("@" + FieldName + 1, FieldType).Value = FieldValue; return((int)DataBaseAccesUtilities.ScalarRequest(Command) != 0); } catch (MySqlException e) { throw new Exception("Field Value Existence Check Failed", e); } finally { MyConnection.Close(); } }