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