Click here to Skip to main content
15,899,314 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
C#
Byte[] bytes = null;
                string text = this.lblId.Text;
                string str18 = this.FileUploadFrontImageR.FileName;
                if (this.FileUploadFrontImageR.HasFile)
                {
                    string filename = FileUploadFrontImageR.PostedFile.FileName;
                    string str20 = text + str18;
                    string filePath = Path.GetFileName(filename);
                    Stream fs = FileUploadFrontImageR.PostedFile.InputStream;
                    BinaryReader br = new BinaryReader(fs);
                    bytes = br.ReadBytes((Int32)fs.Length);
                    ConfigurationManager.ConnectionStrings["ConnectionString"].ToString();
                    connection3 = new SqlConnection(this.strConnectionstring);
                    connection3.Open();
                    SqlCommand cmdddd = new SqlCommand("Update TBL_PRODUCTDETAILS Set Picfront = @Picfront where ID = '" + text + "' ", connection3);
                    cmdddd.Parameters.Add("@Picfront", SqlDbType.Binary).Value = bytes;
                    cmdddd.ExecuteNonQuery();
                }


What I have tried:

i have doing all things as per my knowledge but not getting the image in my image control
Posted
Updated 22-Mar-17 1:47am
v2
Comments
F-ES Sitecore 22-Mar-17 7:11am    
There is nothing in your code that is trying to show the image.

1 solution

There is nothing in your code that has anything to do with images, and the data stored in SQL is just raw byte data. You can read the data from SQL in the usual way and convert it to an image:
C#
MemoryStream ms = new MemoryStream(bytes);
Image myImage = Image.FromStream(ms);
You can them use the Image in any way you deem necessary.
 
Share this answer
 
Comments
Shahbaz435 22-Mar-17 7:49am    
I had added this in my code but its getting me error
OriginalGriff 22-Mar-17 7:53am    
And I'm supposed to know what error it gives you? Presumably, you did make the appropriate changes to make it work in your existing framework?
Shahbaz435 22-Mar-17 7:57am    
Byte[] bytes = null;
string text2 = this.FileUploadFullR.FileName;
string str7 = this.Session["ProductIDA"].ToString();
this.Ade = this.Session["ProductIDA"].ToString();
if (this.FileUploadFullR.HasFile)
{
string filename = FileUploadFullR.PostedFile.FileName;
string str9 = str6 + str4;
string filePath = Path.GetFileName(filename);
Stream fs = FileUploadFullR.PostedFile.InputStream;
BinaryReader br = new BinaryReader(fs);
bytes = br.ReadBytes((Int32)fs.Length);
MemoryStream ms = new MemoryStream(bytes);
Image myImage = Image.FromStream(ms);
ConfigurationManager.ConnectionStrings["ConnectionString"].ToString();
connection = new SqlConnection(this.strConnectionstring);
connection.Open();
SqlCommand cmdddd = new SqlCommand("Update TBL_PRODUCTDETAILS Set Picfront = @Picfront where ID = '" + str6 + "' ", connection);
cmdddd.Parameters.Add("@Picfront", SqlDbType.Binary).Value = bytes;
cmdddd.ExecuteNonQuery();
}
Shahbaz435 22-Mar-17 7:57am    
it gives me error on fromstream

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900