Can you please help me with my requirement
i have created a table Student with the colums sid INT,sname VARCHAR(50),photo which is of varbinary(max) type.
i saved the sid,sname,photo(in binary format) from front end (design page screenshot is attached)
In order to save the photo in binary format i have used very simple code
byte [] data= FileUpload1.FileBytes;
dr[2]=data;
_________________________When i click on Gridview button on design the data from database has to be retrieved...but the main problem is how to convert the binary data to Image so that it is displayed in Gridview
SqlConnection cn;
SqlDataAdapter da;
DataSet ds;
SqlCommandBuilder cmd;
byte[] data;
protected void Page_Load(object sender, EventArgs e)
{
cn = new SqlConnection("server=PRATHAPG\\SQLEXPRESS;database=Prathap;trusted_connection=true");
da = new SqlDataAdapter("select * from student", cn);
cmd = new SqlCommandBuilder(da);
ds = new DataSet();
da.Fill(ds, "stu");
}
protected void btnload_Click(object sender, EventArgs e)
{
if (FileUpload1.HasFile)
{
data = FileUpload1.FileBytes;
DataRow dr = ds.Tables["stu"].NewRow();
dr[0] = txtid.Text;
dr[1] = txtname.Text;
dr[2] = data;
ds.Tables["stu"].Rows.Add(dr);
da.Update(ds, "stu");
}
}
protected void btnshow_Click(object sender, EventArgs e)
{
}
}
Reply |
Reply with attachment |
Alert Moderator