Wrox Programmer Forums
|
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 9th, 2006, 03:46 AM
Registered User
 
Join Date: May 2006
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default Upload and Retrive image from database

I need to upload an image and retrive it with its ID and place it on an image control in a web application. I was able to get the picture on to the form but unable to assin it the the source of the control.I would be glad if someone could help me out.The code is as follows:
private void btnSubmit_Click(object sender, System.EventArgs e)
        {
            if(fileUpload.PostedFile!=null)
            {
                HttpPostedFile File = fileUpload.PostedFile;
                byte[] Data = new Byte[File.ContentLength];
                File.InputStream.Read(Data,0,File.ContentLength);
                object obj = new object();
                obj = Data;
                con = new SqlConnection("server=II-PROXY;database=test;uid=test;pwd=test123");
                con.Open();
                cmd = new SqlCommand("insertImage",con);
                cmd.CommandType=CommandType.StoredProcedure;

                p = new SqlParameter[2];
                p[0] = cmd.Parameters.Add("@img",SqlDbType.Image);
                p[0].Value=obj;
                p[1] = cmd.Parameters.Add("@ans",SqlDbType.VarChar,20);
                p[1].Value=txtAns.Text;

                cmd.ExecuteNonQuery();
                con.Close();

            }

        }

private void btnView_Click(object sender, System.EventArgs e)
        {
            SqlConnection con = new SqlConnection("server=II-PROXY;database=test;uid=test;pwd=test123");
            con.Open();
            cmd = new SqlCommand("select codeImage from Imaging where ID=1",con);
            dr=cmd.ExecuteReader();
            dr.Read();
            byte [] imagestr=(byte[])dr.GetValue(0);
            Response.BinaryWrite(imagestr);
}

Thanks and Regards
Ashok Kumar

ashok





Similar Threads
Thread Thread Starter Forum Replies Last Post
how to retrive image from database gaurav gupta ASP.NET 2.0 Professional 1 July 21st, 2008 10:44 AM
how to upload image into sql server database avnishraj23 General .NET 1 December 4th, 2007 02:20 PM
image upload to a mysql database kevo PHP How-To 3 July 21st, 2007 09:13 AM
How to store & retrive Image in Access table Rahul Gupta VB Databases Basics 0 September 30th, 2005 12:52 AM
Upload image to database or not to database? thachnn SQL Server ASP 0 October 11th, 2004 03:00 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.