예제 #1
0
//------------------------------------------------------------------------------
        //Método BuscarNombre 
        public DataTable BuscarNombre (DPostres Postres)
        {
            DataTable DtResultado = new DataTable("postres");
            SqlConnection SqlCon = new SqlConnection();
            try
            {
                SqlCon.ConnectionString = DConexion.CnBDActivo;
                SqlCommand SqlCmd = new SqlCommand();
                SqlCmd.Connection = SqlCon;
                SqlCmd.CommandText = "sp_buscar_postres";
                SqlCmd.CommandType = CommandType.StoredProcedure;
 


                SqlParameter ParTextoBuscar = new SqlParameter();
                ParTextoBuscar.ParameterName = "@textobuscar";
                ParTextoBuscar.SqlDbType = SqlDbType.VarChar;
                ParTextoBuscar.Size = 50;
                ParTextoBuscar.Value = Postres.TextoBuscar;
                SqlCmd.Parameters.Add(ParTextoBuscar);

                SqlDataAdapter SqlDat = new SqlDataAdapter(SqlCmd);
                SqlDat.Fill(DtResultado);

            }
            catch (Exception ex)
            {
                DtResultado = null;
            }
            return DtResultado;

        }
예제 #2
0
//------------------------------------------------------------------------------
        //Método  
        public DataTable ConsultaDinamica (DPostres Postres)
        {
            DataTable DtResultado = new DataTable("postres");
            SqlConnection SqlCon = new SqlConnection();
            try
            {
                SqlCon.ConnectionString = DConexion.CnBDActivo;
                SqlCommand SqlCmd = new SqlCommand();
                SqlCmd.Connection = SqlCon;
                SqlCmd.CommandText = "sp_postres_Dinamico";
                SqlCmd.CommandType = CommandType.StoredProcedure;
 

                SqlParameter ParConsulta = new SqlParameter();
                ParConsulta.ParameterName = "@consulta";
                ParConsulta.SqlDbType = SqlDbType.VarChar;
                ParConsulta.Size = 500;
                ParConsulta.Value = Postres.Consulta;
                SqlCmd.Parameters.Add(ParConsulta);

                SqlDataAdapter SqlDat = new SqlDataAdapter(SqlCmd);
                SqlDat.Fill(DtResultado);

            }
            catch (Exception ex)
            {
                DtResultado = null;
            }
            return DtResultado;

        }
예제 #3
0
        //-----------------------------------------------------------------------------------
        //Método Accion dinamica
        public string AccionDinamica(DPostres Postres)
        {
            string rpta = "";
            SqlConnection SqlCon = new SqlConnection();
            try
            {
                //Código
                SqlCon.ConnectionString = DConexion.CnBDActivo;
                SqlCon.Open();
                //Establecer el Comando
                SqlCommand SqlCmd = new SqlCommand();
                SqlCmd.Connection = SqlCon;
                SqlCmd.CommandText = "sp_postres_Dinamico";
                SqlCmd.CommandType = CommandType.StoredProcedure;

                SqlParameter ParConsulta = new SqlParameter();
                ParConsulta.ParameterName = @"consulta";
                ParConsulta.SqlDbType = SqlDbType.VarChar;
                ParConsulta.Value = Postres.Consulta;
                SqlCmd.Parameters.Add(ParConsulta);
                //Ejecutamos nuestro comando

                rpta = SqlCmd.ExecuteNonQuery() != 0 ? "OK" : "NO se Elimino el Registro";
            }
            catch (Exception ex)
            {
                rpta = ex.Message;
            }
            finally
            {
if (SqlCon.State == ConnectionState.Open) SqlCon.Close();
            }
            return rpta;
}
예제 #4
0
//-------------------------------------------------------------------------
        //Método MostrarId busca por id y regresa el registro 
        public DataTable MostrarId(DPostres Postres)
        {
            DataTable DtResultado = new DataTable("postres");
            SqlConnection SqlCon = new SqlConnection();
            try
            {
                SqlCon.ConnectionString = DConexion.CnBDActivo;
                SqlCommand SqlCmd = new SqlCommand();
                SqlCmd.Connection = SqlCon;
                SqlCmd.CommandText = "sp_mostrarId_postres";
                SqlCmd.CommandType = CommandType.StoredProcedure;

                SqlParameter ParIdpostre = new SqlParameter();
                ParIdpostre.ParameterName = "@Idpostre";
                ParIdpostre.SqlDbType = SqlDbType.Int;
                ParIdpostre.Value = Postres.Idpostre;
                SqlCmd.Parameters.Add(ParIdpostre);


                SqlDataAdapter SqlDat = new SqlDataAdapter(SqlCmd);
                SqlDat.Fill(DtResultado);

            }
            catch (Exception ex)
            {
                DtResultado = null;
            }
            return DtResultado;

        }
예제 #5
0
        //Método Insertar

        public string Insertar(DPostres Postres)
        {
            string rpta = "";
            SqlConnection SqlCon = new SqlConnection();
            try
            {
                //Código
                SqlCon.ConnectionString = DConexion.CnBDActivo;
                SqlCon.Open();
                //Establecer el Comando
                SqlCommand SqlCmd = new SqlCommand();
                SqlCmd.Connection = SqlCon;
                SqlCmd.CommandText = "sp_insertar_Postres";
                SqlCmd.CommandType = CommandType.StoredProcedure;

                SqlParameter ParIdpostre = new SqlParameter();
                ParIdpostre.ParameterName = "@idpostre";
                ParIdpostre.SqlDbType = SqlDbType.Int;
                ParIdpostre.Value = Postres.Idpostre;
                SqlCmd.Parameters.Add(ParIdpostre);
//
                SqlParameter ParNombre = new SqlParameter();
                ParNombre.ParameterName = "@nombre";
                ParNombre.SqlDbType = SqlDbType.VarChar;
                ParNombre.Value = Postres.Nombre;
                SqlCmd.Parameters.Add(ParNombre);
//
                SqlParameter ParPrecio = new SqlParameter();
                ParPrecio.ParameterName = "@precio";
                ParPrecio.SqlDbType = SqlDbType.Decimal;
                ParPrecio.Value = Postres.Precio;
                SqlCmd.Parameters.Add(ParPrecio);
//
                SqlParameter ParStock = new SqlParameter();
                ParStock.ParameterName = "@stock";
                ParStock.SqlDbType = SqlDbType.Float;
                ParStock.Value = Postres.Stock;
                SqlCmd.Parameters.Add(ParStock);
//

                //Ejecutamos nuestro comando

                rpta = SqlCmd.ExecuteNonQuery() != 0 ? "OK" : "NO se Elimino el Registro";

                
            }
            catch (Exception ex)
            {
                rpta = ex.Message;
            }
            finally
            {
                if (SqlCon.State == ConnectionState.Open) SqlCon.Close();
            }
            return rpta;            

        }