Beispiel #1
0
        //buscar
        public DataTable BuscarNombre(DUnidad Unidad)
        {
            DataTable     DtResultado = new DataTable("unidades");
            SqlConnection SqlCon      = new SqlConnection();

            try
            {
                SqlCon.ConnectionString = Conexion.conexion;
                SqlCommand SqlCmd = new SqlCommand();
                SqlCmd.Connection  = SqlCon;
                SqlCmd.CommandText = "spbuscar_unidad";
                SqlCmd.CommandType = CommandType.StoredProcedure;

                //parametros
                SqlParameter ParTextoBuscar = new SqlParameter();
                ParTextoBuscar.ParameterName = "@textobuscar";
                ParTextoBuscar.SqlDbType     = SqlDbType.VarChar;
                ParTextoBuscar.Size          = 50;
                ParTextoBuscar.Value         = Unidad.Textobuscar;
                SqlCmd.Parameters.Add(ParTextoBuscar);

                SqlDataAdapter SqlDat = new SqlDataAdapter(SqlCmd);
                SqlDat.Fill(DtResultado);
            }
            catch (Exception ex)
            {
                DtResultado = null;
                string valor = ex.ToString();
            }

            return(DtResultado);
        }
Beispiel #2
0
        //metodo insertar
        public string Insertar(DUnidad Unidad)
        {
            string        respuesta = "";
            SqlConnection SqlCon    = new SqlConnection();

            try
            {
                //codigo
                SqlCon.ConnectionString = Conexion.conexion;
                SqlCon.Open();
                SqlCommand SqlCmd = new SqlCommand();
                SqlCmd.Connection  = SqlCon;
                SqlCmd.CommandText = "spinsertar_unidad";
                SqlCmd.CommandType = CommandType.StoredProcedure;

                //parametros
                SqlParameter ParIdUnidad = new SqlParameter();
                ParIdUnidad.ParameterName = "@idunidad";
                ParIdUnidad.SqlDbType     = SqlDbType.Int;
                ParIdUnidad.Direction     = ParameterDirection.Output;
                SqlCmd.Parameters.Add(ParIdUnidad);

                SqlParameter ParNombre = new SqlParameter();
                ParNombre.ParameterName = "@nombre_unidad";
                ParNombre.SqlDbType     = SqlDbType.NVarChar;
                ParNombre.Size          = 100;
                ParNombre.Value         = Unidad.Nombre;
                SqlCmd.Parameters.Add(ParNombre);

                SqlParameter ParDescripcion = new SqlParameter();
                ParDescripcion.ParameterName = "@descripcion_unidad";
                ParDescripcion.SqlDbType     = SqlDbType.NVarChar;
                ParDescripcion.Value         = Unidad.Descripcion;
                SqlCmd.Parameters.Add(ParDescripcion);

                //Ejecutamos el comando
                respuesta = SqlCmd.ExecuteNonQuery() == 1 ? "OK" : "No se Ingresó el Registro.";
            }
            catch (Exception ex)
            {
                respuesta = ex.Message;
            }
            finally
            {
                if (SqlCon.State == ConnectionState.Open)
                {
                    SqlCon.Close();
                }
            }

            return(respuesta);
        }
Beispiel #3
0
        //metodo eliminar
        public string Eliminar(DUnidad Unidad)
        {
            string        respuesta = "";
            SqlConnection SqlCon    = new SqlConnection();

            try
            {
                //codigo
                SqlCon.ConnectionString = Conexion.conexion;
                SqlCon.Open();
                SqlCommand SqlCmd = new SqlCommand();
                SqlCmd.Connection  = SqlCon;
                SqlCmd.CommandText = "speliminar_unidad";
                SqlCmd.CommandType = CommandType.StoredProcedure;

                //parametros
                SqlParameter ParIdUnidad = new SqlParameter();
                ParIdUnidad.ParameterName = "@idunidad";
                ParIdUnidad.SqlDbType     = SqlDbType.Int;
                ParIdUnidad.Value         = Unidad.Idunidad;
                SqlCmd.Parameters.Add(ParIdUnidad);

                //Ejecutamos el comando
                respuesta = SqlCmd.ExecuteNonQuery() == 1 ? "OK" : "No se Eliminó el Registro.";
            }
            catch (Exception ex)
            {
                respuesta = ex.Message;
            }
            finally
            {
                if (SqlCon.State == ConnectionState.Open)
                {
                    SqlCon.Close();
                }
            }

            return(respuesta);
        }