dimarito Posted June 9, 2012 at 02:56 AM Report Share #461588 Posted June 9, 2012 at 02:56 AM boas estou a precisar de ajuda para ler imagens da base de dados com valor binario. estou a usar este codigo mas queria ver todas as imagens existentes na BD em vez de ver so a ultima protected void Page_Load(object sender, EventArgs e) { try { // int imagemID = Convert.ToInt32(Request.QueryString["id"]); //nomeArquivo], [horaUpload], [MIME], [imagem] using (SqlConnection Conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString)) { Conn.Open(); string SQL1 = ("Select count(*) from Imagens"); SqlCommand myCommandCount = new SqlCommand(SQL1, Conn); int a, i = Convert.ToInt32(myCommandCount.ExecuteScalar()); ola.Text = string.Format("{0}", i); for (a = 1; i > a; i--) { const string SQL = "SELECT [MIME], [imagem] FROM [imagens] WHERE [id] = @id"; SqlCommand myCommand = new SqlCommand(SQL, Conn); //myCommand.Parameters.AddWithValue("@id", imagemID); myCommand.Parameters.AddWithValue("@id", i); SqlDataReader myReader = myCommand.ExecuteReader(); if (myReader.Read()) { Response.ContentType = myReader["MIME"].ToString(); Response.BinaryWrite((byte[])myReader["imagem"]); } myReader.Close(); } Conn.Close(); } } catch (Exception ex) { Response.Write(ex.ToString()); } } Link to comment Share on other sites More sharing options...
bruno1234 Posted June 9, 2012 at 12:26 PM Report Share #461622 Posted June 9, 2012 at 12:26 PM Estás a escrever directamente as imagens no response. Não preferes criar várias imagens: <img src="" alt="" /> e afectar só o src de cada uma? Matraquilhos para Android. Gratuito na Play Store. https://play.google.com/store/apps/details?id=pt.bca.matraquilhos Link to comment Share on other sites More sharing options...
dimarito Posted June 9, 2012 at 02:05 PM Author Report Share #461644 Posted June 9, 2012 at 02:05 PM mas assim como e que eu fazia upload das fotos como administrador do site? Link to comment Share on other sites More sharing options...
bruno1234 Posted June 9, 2012 at 02:50 PM Report Share #461647 Posted June 9, 2012 at 02:50 PM Como estás a fazer isso agora? Matraquilhos para Android. Gratuito na Play Store. https://play.google.com/store/apps/details?id=pt.bca.matraquilhos Link to comment Share on other sites More sharing options...
dimarito Posted June 9, 2012 at 03:52 PM Author Report Share #461652 Posted June 9, 2012 at 03:52 PM eu faco upload por um script que guarda na base de dados em valores binarios, mas queria que este script fizesse aparecer todas as imagens e nao so a ultima inserida Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now