Jump to content

fazer galeria em asp


dimarito

Recommended Posts

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.