Hi All,

Hi All,

I have one table in Database.One column is having datatype image .I have insert (image) data the in that means I have insert image in my table .Now I want to show this image in GridView . But with out using any .ashx (Handler file) please tell me how can I do it............

this is the code to insert data

string strImageDesc = txtimagedesc.Text.ToString();

if (FileUpload1.PostedFile != null && FileUpload1.PostedFile.FileName != "")
{
byte[] imageSize = new byte
[FileUpload1.PostedFile.ContentLength];
HttpPostedFile uploadedImage = FileUpload1.PostedFile;
uploadedImage.InputStream.Read(imageSize, 0, (int)FileUpload1.PostedFile.ContentLength);

// Create SQL Command
SqlCommand cmd = new SqlCommand();
// cmd.CommandText = "INSERT INTO Images(ImageName,Image)" +" VALUES (@ImageName,@Image)";

cmd.CommandText = "INSERT INTO Nop_FlashBanner(ImageName,FlashImage,ImageDesc,CustomerID,Flag,PostedDate)" + "Values(@ImageName,@FlashImage,@ImageDesc,@CustomerID,@Flag,@PostedDate)";

cmd.CommandType = CommandType.Text;
cmd.Connection = con;

SqlParameter ImageName = new SqlParameter
("@ImageName", SqlDbType.VarChar, 50);
ImageName.Value = "Door";
cmd.Parameters.Add(ImageName);

SqlParameter UploadedImage = new SqlParameter
("@FlashImage", SqlDbType.Image, imageSize.Length);
UploadedImage.Value = imageSize;
cmd.Parameters.Add(UploadedImage);

SqlParameter ImageDesc = new SqlParameter
("@ImageDesc", SqlDbType.VarChar, 250);
ImageDesc.Value = strImageDesc.ToString();
cmd.Parameters.Add(ImageDesc);

SqlParameter CustomerID = new SqlParameter
("@CustomerID", SqlDbType.Int);
CustomerID.Value = 1;
cmd.Parameters.Add(CustomerID);

SqlParameter Flag = new SqlParameter
("@Flag", SqlDbType.VarChar, 50);
Flag.Value = "Flase";
cmd.Parameters.Add(Flag);

SqlParameter PostedDate = new SqlParameter
("@PostedDate", SqlDbType.DateTime);
PostedDate.Value = System.DateTime.Now;
cmd.Parameters.Add(PostedDate);


con.Open();
int result = cmd.ExecuteNonQuery();
con.Close();
if (result > 0)
lblMessage.Text = "File Uploaded";

This is the GridView to show data

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataSourceID="SqlDataSource1">
<Columns>
<asp:BoundField DataField="ImageName" HeaderText="ImageName"
SortExpression="ImageName" />
<asp:BoundField DataField="ImageDesc" HeaderText="ImageDesc"
SortExpression="ImageDesc" />
<asp:BoundField DataField="FlashID" HeaderText="FlashImage"
SortExpression="FlashImage"
DataFormatString="FlashBanner.aspx?ImageId={0}" />
<asp:ImageField DataImageUrlField="FlashID"
DataImageUrlFormatString="../Administration/FlashBanner.aspx?ImageId={0}">
</asp:ImageField>
<asp:ImageField DataImageUrlField="FlashID" HeaderText="Flash Image"
DataImageUrlFormatString="../NopCommerceStore/Administration/FlashBanner.aspx">
<ItemStyle Height="100px" Width="800px" />
</asp:ImageField>
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:SeedSpwanDBConnectionString %>"
SelectCommand="SELECT * FROM [Nop_FlashBanner]"></asp:SqlDataSource>

<asp:GridView ID="FlashBannerGridView" runat="server" AutoGenerateColumns="False" Width="100%">
<Columns>
<asp:TemplateField HeaderText="Name"
ItemStyle-Width="20%">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text=' <%# Eval("ImageName")%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="FlashImage"
ItemStyle-Width="16%">
<ItemTemplate>
<asp:Image ID="Image1" Width="400px" Height="150px" runat="server"
ImageUrl='<%# "../NopCommerceStore/Administration/Handler/FlashHandler.ashx?ImageId=" + Eval ("FlashID") %>' />

</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="ImageDesc"
ItemStyle-Width="16%">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("ImageDesc")%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>

</Columns>
</asp:GridView>

and also this is I have done in .ashx file

public void ProcessRequest(HttpContext context)
{
//context.Response.ContentType = "text/plain";
//context.Response.Write("Hello World");

SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["NopSqlConnection"].ConnectionString);
con.Open();
string sql = "Select * from Nop_FlashBanner where where FlashID=@ImageId ";
SqlCommand cmd = new SqlCommand(sql, con);
cmd.Parameters.Add("@ImageId", SqlDbType.Int).Value = context.Request.QueryString["id"];
cmd.Prepare();
SqlDataReader dr = cmd.ExecuteReader();
dr.Read();
//context.Response.ContentType = dr["Image_Type"].ToString();
context.Response.BinaryWrite((byte[])dr["FlashImage"]);
dr.Close();
con.Close();
}