コード例 #1
0
        /// <summary>
        /// Delete by primary key
        /// </summary>
        /// <param name="keys">primary keys</param>
        /// <returns>true for successfully deleted</returns>
        public bool Delete(BENHKeys keys)
        {
            SqlCommand sqlCommand = new SqlCommand();

            sqlCommand.CommandText = "dbo.[BENH_DeleteByPrimaryKey]";
            sqlCommand.CommandType = CommandType.StoredProcedure;

            // Use connection object of base class
            sqlCommand.Connection = MainConnection;

            try
            {
                sqlCommand.Parameters.Add(new SqlParameter("@ID", SqlDbType.Int, 4, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed, keys.ID));


                MainConnection.Open();

                sqlCommand.ExecuteNonQuery();

                return(true);
            }
            catch              //(Exception ex)
            {
                return(false); //throw new Exception("BENH::DeleteByKey::Error occured.", ex);
            }
            finally
            {
                MainConnection.Close();
                sqlCommand.Dispose();
            }
        }
コード例 #2
0
        /// <summary>
        /// Select by primary key
        /// </summary>
        /// <param name="keys">primary keys</param>
        /// <returns>BENH business object</returns>
        public BENH SelectByPrimaryKey(BENHKeys keys)
        {
            SqlCommand sqlCommand = new SqlCommand();

            sqlCommand.CommandText = "dbo.[BENH_SelectByPrimaryKey]";
            sqlCommand.CommandType = CommandType.StoredProcedure;

            // Use connection object of base class
            sqlCommand.Connection = MainConnection;

            try
            {
                sqlCommand.Parameters.Add(new SqlParameter("@ID", SqlDbType.Int, 4, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed, keys.ID));


                MainConnection.Open();

                IDataReader dataReader = sqlCommand.ExecuteReader();

                if (dataReader.Read())
                {
                    BENH businessObject = new BENH();

                    PopulateBusinessObjectFromReader(businessObject, dataReader);

                    return(businessObject);
                }
                else
                {
                    return(null);
                }
            }
            catch             //(Exception ex)
            {
                return(null); //throw new Exception("BENH::SelectByPrimaryKey::Error occured.", ex);
            }
            finally
            {
                MainConnection.Close();
                sqlCommand.Dispose();
            }
        }