0

i need to display an image stored in mysql db as a blob field using ODBC connection in ASP page with C#. Please help me

<%@ WebHandler Language="C#" Class="stdImg" %>

using System; using System.Web;

public class stdImg : IHttpHandler {

public void ProcessRequest(HttpContext context)
{


    System.Data.Odbc.OdbcConnection con = new System.Data.Odbc.OdbcConnection();
    con.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["sis"].ConnectionString;


    con.Open();
    System.Data.Odbc.OdbcCommand cmd = con.CreateCommand();
    cmd.CommandText = "SELECT PHOTOGRAPH FROM student_mast WHERE ADMISSION_NO='1000000001'";


    byte[] buf = (byte[])cmd.ExecuteScalar();


    context.Response.Clear();
    context.Response.OutputStream.Write(buf, 0, buf.Length);
    context.Response.ContentType = "image/jpeg";
    context.Response.BinaryWrite(buf);
}

public bool IsReusable
{
    get
    {
        return false;
    }
}

}

1 Answer 1

1

Use Connection string like this

<add name="MYSQLConnectionString" connectionString="Driver={MySQL ODBC 3.51 Driver};database=DB;option=0;pwd=pwd;port=3306;server=yourserver;uid=user;sslverify=0"
   providerName="System.Data.Odbc" />

First Install the ODBC driver for MYSQl

here is download link

http://dev.mysql.com/downloads/connector/odbc/3.51.html

Update use data grid and make connection to DB and in data grid use this code

 <asp:TemplateColumn  HeaderText="Image">
         <ItemTemplate >
            <img runat="server" 
                 src='<%# "getImage.aspx?ID=" + DataBinder.Eval(Container.DataItem, 
                 "ImageIdentity")  %>' ID="Img1"/>
         </ItemTemplate>
     </asp:TemplateColumn>

verify your image field name

Sign up to request clarification or add additional context in comments.

4 Comments

I have installed it and all other connections are working fine. I want to know How to display a blob image in asp page
Please Show Clearly which version of asp u r using ? Is this asp.net or asp
Its ASP.net with VS 2008 i added the code i am working on above
Thank You very much All for the help. I resolved the problem :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.