コード例 #1
0
        public int CadastraOcorrencia(Ocorrencia o)
        {
            string sql = "INSERT INTO ocorrencia ([justificativa], [status], [codPonto]) VALUES (@justificativa, @status, @codPonto);";

            int result;

            SqlConnection conn   = new SqlConnection(strConnection);
            SqlCommand    sqlcmd = new SqlCommand(sql, conn);

            sqlcmd.Parameters.AddWithValue("@justificativa", o.GetJustificativa());
            sqlcmd.Parameters.AddWithValue("@status", o.GetStatus());
            sqlcmd.Parameters.AddWithValue("@codPonto", o.GetCodPonto());

            try
            {
                conn.Open();

                //verifica se possui algum resultado na consulta
                result = sqlcmd.ExecuteNonQuery();
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                conn.Close();
            }
            return(result);
        }