Exemplo n.º 1
0
        public string Insertar(DCategoria Categoria)
        {
            string        rpta   = "";
            SqlConnection SqlCon = new SqlConnection();

            try
            {
                SqlCon.ConnectionString = AccesoDatos.Conexion.cadena;

                SqlCon.Open();

                string cadenasql = string.Empty;
                cadenasql = "INSERT INTO [dbo].[Categories] (CategoryName , Description , Picture)";
                cadenasql = cadenasql + " VALUES ('" + Categoria.CategoryName + "', ";
                cadenasql = cadenasql + "' " + Categoria.Description + "',";
                cadenasql = cadenasql + "' " + Categoria.Picture + "') ";


                //Establecer el Comando
                SqlCommand comando = SqlCon.CreateCommand();

                comando.CommandText = cadenasql;

                //Ejecutamos nuestro comando

                rpta = comando.ExecuteNonQuery() == 1 ? "OK" : "NO se Actualizo el Registro";
            }
            catch (Exception ex)
            {
                rpta = ex.Message;
            }
            finally
            {
                if (SqlCon.State == ConnectionState.Open)
                {
                    SqlCon.Close();
                }
            }

            return(rpta);
        }
Exemplo n.º 2
0
        public DataTable BuscarCategoria(DCategoria Categoria)
        {
            DataTable     DtResultado = new DataTable("[dbo].[Categories]");
            SqlConnection SqlCon      = new SqlConnection();

            try
            {
                SqlCon.ConnectionString = AccesoDatos.Conexion.cadena;

                SqlCon.Open();
                string cadenasql = string.Empty;
                cadenasql = "SELECT CategoryID , CategoryName, Description , Picture FROM [dbo].[Categories] ";
                cadenasql = cadenasql + "WHERE CategoryName LIKE '" + Categoria.TextoBuscar + "%'";


                //Establecer el Comando

                SqlCommand comando = new SqlCommand();

                comando.Connection  = SqlCon;
                comando.CommandText = cadenasql;
                SqlDataAdapter SqlDat = new SqlDataAdapter(comando);
                SqlDat.Fill(DtResultado);
            }
            catch (Exception ex)
            {
                DtResultado = null;
            }
            finally
            {
                if (SqlCon.State == ConnectionState.Open)
                {
                    SqlCon.Close();
                }
            }
            return(DtResultado);
        }