Click here to Skip to main content
16,021,294 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have two file upload controls and a button


file upload one used to upload one image


file upload one used to upload another image

when i click submit .. i need to store both images in sql...



Then i need to retrieve image back to form using image control ....

Help me if possible dear friends...
Posted

This is an easy task, which has nothing to do with your upload controls ( it's just storing an image in SQL ) and is widely documented on the web. What have you tried ? Why do you want to store the images and not the paths to image files. This DOES mean you'll need to write a page which returns the image bytes based on an id, that IS a web based task you'll need to perform to make it work this way.

It's worth mentioning that you've been asking variations of this question since Dec 24. Are you still really no closer to a solution ? What have you been doing all this time ?
 
Share this answer
 
v2
using single file upload i got it.. to add multiple files i need yar...
protected void Button1_Click(object sender, EventArgs e)
   {
       int imagelen = FileUpload1.PostedFile.ContentLength;
       byte[] picbyte = new byte[imagelen];
       FileUpload1.PostedFile.InputStream.Read(picbyte, 0, imagelen);
       //Upload1.PostedFile.InputStream.Read(picbyte, 0, imagelen);

       SqlConnection conn = new SqlConnection("server=SRM02;database=image;integrated security=true");
       try
       {
           conn.Open();
           SqlCommand cmd = new SqlCommand("insert into Imagetable" +" (Image1,id) " +" values (@pic, @imageid)",conn);
           cmd.Parameters.Add("pic", picbyte);
           cmd.Parameters.Add("@imageid", TextBox1.Text);

           cmd.ExecuteNonQuery();
       }
       finally
       {
           conn.Close();
       }
   }
 
Share this answer
 
v2
I'm not sure why you're still adding fake answers instead of editing your post. OK, so your question is not remotely what you asked at all. I don't see how you have a question at all. You have two upload controls. You have code that works for one. Why can't you apply your code to both ? What is your SPECIFIC problem ? Is it working out if two files were uploaded ? If not that, I am at a loss to see how you could have an issue if your code for one upload works fine.
 
Share this answer
 
Weird - you answered twice but they were deleted. Do you still need help ? Did you figure out how to call your method twice if you have two files ?
 
Share this answer
 
Dear Friend Atlast i got it to upload two files using two upload controls

protected void Button1_Click(object sender, EventArgs e)
{
if ((FileUpload1.FileName != null) && (FileUpload2.FileName != null))
{
int imagelen = FileUpload1.PostedFile.ContentLength;
int imagelen1 = FileUpload2.PostedFile.ContentLength;
byte[] picbyte = new byte[imagelen];
byte[] picbyte1 = new byte[imagelen1];

FileUpload1.PostedFile.InputStream.Read(picbyte, 0, imagelen);
FileUpload2.PostedFile.InputStream.Read(picbyte1, 0, imagelen1);

SqlConnection conn = new SqlConnection("server=SRM02;database=xyz;integrated security=true");
try
{
conn.Open();
SqlCommand cmd = new SqlCommand("insert into img" + " (Image1,image2) " + " values (@pic1,@pic2 )", conn);
cmd.Parameters.Add("pic1", picbyte);
cmd.Parameters.Add("pic2", picbyte1);


cmd.ExecuteNonQuery();
}
finally
{
conn.Close();
}

}
}

I tried and found.. Thanks for reply May be this useful to some one.....
 
Share this answer
 

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