hey i am able to store image into sql server but unable to display back on image control in aspx page. any suggestion will be thnkful..
i hv to display image, id & name on other page for ex: display.aspx. how can i do ths????
i am providing my SP and Code wat i hv writtn...
SP:
insert into DB :
ALTER PROCEDURE [dbo].[insertIntoImage](@id int,@name nvarchar (30),@image image)
AS
TRY
INSERT INTO image(imageid,name,images) VALUES (@id,@name,@image);
END;
Retrieve image:
AS
BEGIN
select imageid,images,name from image where imageid=@id
SET NOCOUNT ON;
code ....
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
public partial class Account_insert : System.Web.UI.Page
{
int Id;
string strName;
byte[] myimage;
SqlConnection conn = new SqlConnection("Data Source=.;Initial Catalog=demo_db;Integrated Security=true");
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnSubmit_Click(object sender, EventArgs e)
{
getInfo();
displayInfo();
}
public void getInfo()
{
Id = 0;
if(txtId.Text!="")
Id = Convert.ToInt32(txtId.Text);
strName = txtName.Text;
if (FileUpload1.PostedFile != null && FileUpload1.PostedFile.FileName != "")
{
byte[] myimage = new byte[FileUpload1.PostedFile.ContentLength];
HttpPostedFile Image = FileUpload1.PostedFile;
Image.InputStream.Read(myimage, 0, (int)FileUpload1.PostedFile.ContentLength);
try
{
conn.Open();
SqlCommand cmdInsert = new SqlCommand("insertIntoImage", conn);
cmdInsert.CommandType = CommandType.StoredProcedure;
cmdInsert.Parameters.Add("@id", Id);
cmdInsert.Parameters.Add("@name", strName);
cmdInsert.Parameters.Add("@image", SqlDbType.Image, myimage.Length).Value = myimage;
cmdInsert.Parameters["@image"].Value = myimage;
cmdInsert.ExecuteNonQuery();
cmdInsert.Dispose();
}
catch (Exception ee)
{
ee.Message.ToString();
}
finally
{
conn.Close();
}
}
}
}