コード例 #1
0
        public static Preguntas TraerPregunta(int Id)
        {
            Preguntas     unacategoria = new Preguntas();
            SqlConnection Conexion     = Conectar();
            SqlCommand    consulta     = Conexion.CreateCommand();

            consulta.CommandType = System.Data.CommandType.StoredProcedure;
            consulta.CommandText = "sp_TraerPregunta";
            consulta.Parameters.AddWithValue("@pIdPregunta", Id);
            SqlDataReader lector = consulta.ExecuteReader();

            if (lector.Read())
            {
                string Texto;
                Texto = lector["Texto"].ToString();
                unacategoria.Texto = lector["Texto"].ToString();
            }
            return(unacategoria);
        }
コード例 #2
0
        public static bool InsertarPreguntas(Preguntas P)
        {
            bool          a        = false;
            SqlConnection Conexion = Conectar();
            SqlCommand    consulta = Conexion.CreateCommand();

            consulta.CommandType = System.Data.CommandType.StoredProcedure;
            consulta.CommandText = "sp_CrearPregunta";
            consulta.Parameters.AddWithValue("@pPregunta", P.Texto);
            consulta.Parameters.AddWithValue("@pCatPreg", P.IdCategoria);
            int regsAfectados = consulta.ExecuteNonQuery();

            if (regsAfectados == 1)
            {
                a = true;
            }
            Desconectar(Conexion);
            return(a);
        }
コード例 #3
0
        public static List <Preguntas> TraerPreguntas(Preguntas P)
        {
            List <Preguntas> C = new List <Preguntas>();
            Preguntas        cat;
            SqlConnection    Conexion = Conectar();
            SqlCommand       consulta = Conexion.CreateCommand();

            consulta.CommandType = System.Data.CommandType.StoredProcedure;
            consulta.CommandText = "sp_VerPreguntas";
            SqlDataReader lector = consulta.ExecuteReader();

            while (lector.Read())
            {
                cat             = new Preguntas();
                cat.IdPregunta  = Convert.ToInt32(lector["IdPregunta"]);
                cat.Texto       = lector["Texto"].ToString();
                cat.IdCategoria = Convert.ToInt32(lector["IdCateggoria"]);
                C.Add(cat);
            }
            Desconectar(Conexion);
            return(C);
        }