Beispiel #1
0
        public static void UpdateScorFinalSondaj(Sondaj sondaj)
        {
            //---------------------< Actualizeaza scorul unui sondaj >---------------------------

            SqlConnection Connection = new SqlConnection(ConnectionString);

            try
            {
                //Vom folosi parametri sql pentru ca aplicatia sa fie imuna atacurilor de tip SQL Injection
                SqlCommand cmd = new SqlCommand("sp_UpdateScorFinalSondaj", Connection);
                cmd.CommandType = CommandType.StoredProcedure;

                SqlParameter parScor = new SqlParameter("@ScorFinal", sondaj.ScorFinal);
                cmd.Parameters.Add(parScor);

                SqlParameter parIdSondaj = new SqlParameter("@IdSondaj", sondaj.IdSondaj);
                cmd.Parameters.Add(parIdSondaj);

                Connection.Open();
                cmd.ExecuteNonQuery();
                Connection.Close();
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Eroare Update Sondaj: " + ex.Message);
                throw ex;
            }
            finally
            {
                if (Connection.State == ConnectionState.Open)
                {
                    Connection.Close();
                }
            }
        }
Beispiel #2
0
        public static void InsertSondaj(Sondaj sondaj)
        {
            //---------------------< Insereaza un sondaj in baza de date >---------------------------

            SqlConnection Connection = new SqlConnection(ConnectionString);

            try
            {
                SqlCommand cmd = new SqlCommand("sp_InsertSondaj", Connection);
                cmd.CommandType = CommandType.StoredProcedure;

                SqlParameter parParticipant = new SqlParameter("@IdParticipant", sondaj.IdParticipant);
                cmd.Parameters.Add(parParticipant);

                SqlParameter parScorFinal = new SqlParameter("@ScorFinal", sondaj.ScorFinal);
                cmd.Parameters.Add(parScorFinal);

                SqlParameter parData = new SqlParameter("@Data", sondaj.Data);
                cmd.Parameters.Add(parData);

                Connection.Open();
                cmd.ExecuteNonQuery();
                Connection.Close();
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Error inserting Sondaj: " + ex.Message);
                if (Connection.State == ConnectionState.Open)
                {
                    Connection.Close();
                }
            }
        }