diogom Posted April 6, 2012 at 03:56 PM Report Share #447929 Posted April 6, 2012 at 03:56 PM olá, Estou a fazer um site e utilizo uma gridview. O problema é que não consigo carregar as fotos da base de dados para a gridview, o restante carrega sem problema. O codigo: protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { carregardados(); } } public void carregardados() { //Ocultar resultados GridView1.Visible = false; //Label1.Text = ""; string query = ("SELECT * FROM imagens"); String SERVIDOR = "localhost"; String BANCO = ""; String USUARIO = ""; String SENHA = ""; String stringConexao = "Database=" + BANCO + ";Data Source=" + SERVIDOR + ";User Id=" + USUARIO + ";Password=" + SENHA + "; pooling=false"; MySqlConnection conexao = new MySqlConnection(stringConexao); MySqlDataAdapter myAdapter = new MySqlDataAdapter(); DataSet dataset = new DataSet(); try { myAdapter.SelectCommand = new MySqlCommand(query, conexao); myAdapter.Fill(dataset); GridView1.DataSource = dataset; GridView1.DataBind(); GridView1.Visible = true; } catch (MySqlException erro) { // Label1.Text = erro.Message; MessageBox.Show("erro " + erro); } finally { dataset.Dispose(); myAdapter.Dispose(); conexao.Close(); conexao.Dispose(); } } } Link to comment Share on other sites More sharing options...
petvetbr Posted April 6, 2012 at 04:05 PM Report Share #447933 Posted April 6, 2012 at 04:05 PM Para carregar imagens é um pouco mais complicado do que simplemente aplicar o DataSet no GridView. Veja os artigos abaixo: http://www.codeproject.com/Articles/20782/Displaying-Images-from-a-Database-in-a-GridView http://www.aspsnippets.com/Articles/Display-images-from-SQL-Server-Database-in-ASP.Net-GridView-control.aspx http://www.codedigest.com/Articles/ASPNET/6_GridView_with_Image.aspx Fernando Lage Bastos - MCP/MCTS/MCPD Link to comment Share on other sites More sharing options...
poliveira1978 Posted April 6, 2012 at 11:09 PM Report Share #447983 Posted April 6, 2012 at 11:09 PM podes usar o objecto asp:image no ficheiro aspx e defines a propriedade ImageUrl da seguinte forma: ImageUrl='<%#Eval("nome do campo da imagem na bd")%>' Link to comment Share on other sites More sharing options...
diogom Posted April 8, 2012 at 10:58 AM Author Report Share #448097 Posted April 8, 2012 at 10:58 AM obrg 😉 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