This is the aspx.cs page code
protected void btnadd_Click(object sender, EventArgs e)
{
string qu;
if (fileupload.PostedFile != null &&
fileupload.PostedFile.FileName != "")
{
byte[] imageSize = new byte
[fileupload.PostedFile.ContentLength];
HttpPostedFile uploadedImage = fileupload.PostedFile;
uploadedImage.InputStream.Read
(imageSize, 0, (int)fileupload.PostedFile.ContentLength);
conn.connect();
qu = "insert into Prod_detail1 values ('" + txtprodid.Text + "','" + txtprodcatid.Text + "','" + txtprodname.Text + "','" + txtproddesc.Text + "',@Image,'" + txtprice.Text + "','" + txtstatus.Text + "')";
conn.cmd = new System.Data.SqlClient.SqlCommand(qu, conn.con);
SqlParameter UploadedImage = new SqlParameter("@Image", SqlDbType.Image, imageSize.Length);
UploadedImage.Value = imageSize;
conn.cmd.Parameters.Add(UploadedImage);
conn.cmd.ExecuteNonQuery();
fill();
}
}
public void fill()
{
conn.con = new SqlConnection(conn.str1);
conn.ad = new System.Data.SqlClient.SqlDataAdapter("select Prod_code,Prod_cate_id,Prod_name,Prod_desc,Prod_image,Price from Prod_detail1 where Prod_code='" + Request.QueryString["Prod_code"]+"'", conn.con);
conn.ds = new DataSet();
conn.ad.Fill(conn.ds);
GridView1.DataSource = conn.dr;
GridView1.DataBind();
conn.con.Close();
DisplayImage();
}
private void DisplayImage()
{
if (Request.QueryString["Prod_code"] != null)
{
conn.con.Open();
conn.ad = new SqlDataAdapter("select Prod_image from Prod_detail1 where id='" + Request.QueryString["Prod_code"] + "'", conn.con);
DataTable dt = new DataTable();
conn.ad.Fill(dt);
conn.con.Close();
Byte[] bytes = (Byte[])dt.Rows[0]["Prod_image"];
Response.BinaryWrite(bytes);
}
}
this is the aspx page code
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="add_prod.aspx.cs" Inherits="add_prod" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">
.style1
{
width: 100%;
height: 50%;
border: 2px solid #808000;
background-color: #c0c0c0;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<table cellpadding="2" class="style1">
<tr>
<td>
Product id:</td>
<td>
<asp:TextBox ID="txtprodid" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
Product category id:</td>
<td>
<asp:TextBox ID="txtprodcatid" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
Product Name:</td>
<td>
<asp:TextBox ID="txtprodname" runat="server" ></asp:TextBox>
</td>
</tr>
<tr>
<td>
Product description:</td>
<td>
<asp:TextBox ID="txtproddesc" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
Product image:</td>
<td>
<asp:FileUpload ID="fileupload" runat="server" /> </td>
</tr>
<tr>
<td>
Price:</td>
<td>
<asp:TextBox ID="txtprice" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
Status:</td>
<td>
<asp:TextBox ID="txtstatus" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
</td>
<td>
</td>
</tr>
<tr>
<td>
</td>
<td>
<asp:Button ID="btnadd" runat="server" onclick="btnadd_Click"
Text="add product" />
</td>
</tr>
<tr>
<td>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataKeyNames="Prod_code" DataSourceID="SqlDataSource1">
<Columns>
<asp:BoundField DataField="Prod_code" HeaderText="Prod_code" ReadOnly="True"
SortExpression="Prod_code" />
<asp:BoundField DataField="Prod_cate_id" HeaderText="Prod_cate_id"
SortExpression="Prod_cate_id" />
<asp:BoundField DataField="Prod_name" HeaderText="Prod_name"
SortExpression="Prod_name" />
<asp:BoundField DataField="Prod_desc" HeaderText="Prod_desc"
SortExpression="Prod_desc" />
<asp:TemplateField HeaderText="Image">
<ItemTemplate>
<asp:Image ID="Image1" runat="server"
ImageUrl='<%# Eval("Prod_code", "add_prod.aspx?Prod_code={0}")%>'/>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Price" HeaderText="Price" SortExpression="Price" />
<asp:BoundField DataField="Status" HeaderText="Status"
SortExpression="Status" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:centurydbConnectionString %>"
SelectCommand="SELECT * FROM [Prod_detail1]"></asp:SqlDataSource>
</td>
<td>
</td>
</tr>
<tr>
<td>
</td>
<td>
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
Now can you advise me something ravi