fazer galeria em asp.net c#

dimarito

Membro
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


Código:
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());
            }
    }
 
Boas
Porque estás a utilizar o loop ao contrário (decrementar o "i")?Penso que há aí confusão com os valores...coloca o loop a incrementar,é mais fácil:
Código:
for(a = 1; a <= i; a++)
Cumps
 
Back
Topo