Exemplo n.º 1
0
        public static Instruction Create(string name)
        {
            Instruction instruction;
            // Insert new instruction
            using (SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["SqlServer"].ConnectionString))
            {
                using (SqlCommand command = new SqlCommand("dbo.Instruction_Insert", connection))
                {
                    command.CommandType = CommandType.StoredProcedure;
                    //command.Parameters.AddWithValue("@InstructionID", 0).Direction = ParameterDirection.Output;
                    command.Parameters.Add("@InstructionID", SqlDbType.Int);
                    command.Parameters["@InstructionID"].Direction = ParameterDirection.Output;
                    command.Parameters.AddWithValue("@InstructionName", name);

                    connection.Open();
                    command.ExecuteNonQuery();
                    instruction = new Instruction((int)command.Parameters["@InstructionID"].Value, name);
                    connection.Close();
                } // SqlCommand
            } // SqlConnection
            return instruction;
        }
Exemplo n.º 2
0
        public static Instruction GetInstructionByID(int id)
        {
            Instruction instruction = null;
            // Select instruction
            using (SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["SqlServer"].ConnectionString))
            {
                using (SqlCommand command = new SqlCommand("db_datareader.Instruction_Select", connection))
                {
                    command.CommandType = CommandType.StoredProcedure;
                    command.Parameters.AddWithValue("@InstructionID", id);
                    connection.Open();

                    using (SqlDataReader dataReader = command.ExecuteReader())
                    {
                        if (dataReader.HasRows && dataReader.Read())
                        {
                            instruction = new Instruction(id,
                                                        (string)dataReader["InstructionName"]
                                                        );
                        }
                    } // SqlDataReader
                } // SqlCommand
            } // SqlConnection
            return instruction;
        }