borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder

AndreaVB | Forum | News | Downloads | Register | Help | Member List | Statistics | Search | PM | Profile

Print This Topic
Previous Topic (Login)Next Topic (how to create and bind datagrid writing code in asp.net) New Topic New Poll Post Reply
AndreaVB Forum : ASP.Net : Problem displaying images from database
Poster Message
zimcoder
Level: VB Lord


Registered: 27-10-2003
Posts: 225

icon Problem displaying images from database

Hi all
I have uploaded images to an SQL Server database in binary format and would like to display the images in my page via a datalist. I have followed some of the examples online but i have not been successful
here is the Coode that is reading my database and attempting to display the images ..

public class ReturnImage : System.Web.UI.Page
{
private void Page_Load(object sender, System.EventArgs e)
{
string productID = Request.QueryString["productID"].ToString();
int prodID = Int32.Parse(productID);
string sqlText = "Select ThumbNail,ContentType FROM Prducts WHERE ProductID="+prodID;

SqlConnection conn = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]);
SqlCommand command = new SqlCommand(sqlText,conn);

conn.Open();
SqlDataReader reader = command.ExecuteReader();
if(reader.Read())            {
Response.Clear();
Response.ContentType = reader["ContentType"].ToString();
Response.BinaryWrite((byte[])reader["ThumbNail"]);
Response.Close();
}
reader.Close();
conn.Close();
}
}


this page is called from the img tag that is meant to  diplay the actual image.


<img  height=75 src='ReturnImage.aspx?productID=<%# DataBinder.Eval(Container.DataItem, "ProductID") %>' width=100 Border=1>

the enctype on the form has been set like this enctype="multipart"

am i missing something?


____________________________
BrainBench ADO.NET and ASP.NET Certified Developer

20-01-2004 at 09:04 AM
View Profile Send Email to User Show All Posts | Quote Reply
zimcoder
Level: VB Lord


Registered: 27-10-2003
Posts: 225
icon Re: Problem displaying images from database

I finally managed to solve this one. I deciced instead to upload the images into a folder on the web server and store the paths and names in the database as strings. The solution has proven effective

____________________________
BrainBench ADO.NET and ASP.NET Certified Developer

28-04-2004 at 10:01 PM
View Profile Send Email to User Show All Posts | Quote Reply
fabulous
Level: VB Guru


Registered: 03-08-2002
Posts: 439
icon Re: Problem displaying images from database

I have a sample app done in VB.NET to do the same using an access DB. It saves the actual images in .Jpeg format to the database.

Using SQL Server is a matter of changing the provider:

instead of System.Data.OleDb use System.Data.SqlClient:

Where I used any OleDbType you must use a SqlDbType property. I will make the same code in C# shortly and upload it here for anyone who may want to do the same.

____________________________
My boss is a Jewish Carpenter (Jesus Christ)


Brain Bench Certified VB.NET Developer

____________________________
Attached:
ImagesDB.zip 42 KB (Downloads: 3)

20-07-2004 at 08:29 AM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
AndreaVB Forum : ASP.Net : Problem displaying images from database
Previous Topic (Login)Next Topic (how to create and bind datagrid writing code in asp.net) New Topic New Poll Post Reply
Surf To:


Not Logged In? Username: Password: Lost your password?
Partners: Download Actual Software | Free Software Download
borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder