Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#2.0
Hi dudes

I am a beginner of c#.So i want a full explain and coding of how to load a image in database.
Posted 14-Oct-12 21:20pm
Comments
   
we can upload image in database not load..........
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 5

Such question have been ask'e so many times on this website, see here[^].
 
I hope you're not beginner to google[^], try there first and then post your questions if you get stuck'd somewhere. This is not at all appropriate. Give a try at least.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

put a file upload control,Two textboxes txtImagid,txtImageName ,Upload button
 

StoreImages is table with imageid int,imagename vachar(20), myimage image
 
Write the below code in upload button click
 

protected void UploadImage_Click(object sender, EventArgs e)
   {
       int retValue = 0;
 
       byte[] buffer=new byte[(int)fileUpload1.FileContent.Length];
 
       fileUpload1.FileContent.Read(buffer, 0, buffer.Length);
 
       string SqlCmd = "insert into StoreImages(imageid,ImageName,MyImage) values(@id,@Name,@MyImage)";
 
       using (SqlConnection con = new SqlConnection(ConnString))
       {
           using (SqlCommand cmd = new SqlCommand(SqlCmd, con))
           {
               SqlParameter[] prm = new SqlParameter[3];
               prm[0] = new SqlParameter("@id", SqlDbType.Int);
               prm[0].Value = txtImgId.Text.Trim();
               prm[1] = new SqlParameter("@Name", SqlDbType.VarChar,20);
               prm[1].Value = fileUpload1.FileName;
               prm[2] = new SqlParameter("@MyImage", SqlDbType.VarBinary);
               prm[2].Value = buffer;
               cmd.Parameters.AddRange(prm);
               con.Open();
               try
               {
                   retValue = cmd.ExecuteNonQuery();
                   if (retValue != 0)
                   {
                       Response.Write("Successfully uploaded");
                   }
                   else
                   {
                       Response.Write("Not uploaded");
                   }
                   con.Close();
               }
               catch (Exception ee)
               {
                   Response.Write(ee.Message + "");
               }
           }
       }
   }
  Permalink  
v3
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

You may wish to put what technology as your question is very loose in definition.
 
I would suggest you look at Working with SQL Server BLOB Data in .NET[^]. This should get you started with BLOB's and ADO.NET
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

SqlDataAdapter da;
DataSet ds = new DataSet();
protected void Page_Load(object sender, EventArgs e)
{
PhotoPanel.Visible = true;
SubmitLabel.Visible = false;
}
protected void SubmitLinkButton_Click(object sender, EventArgs e)
{

 
if (PhotoFileUpload.HasFile)
{
string str1 = PhotoFileUpload.FileName;
string str2 = Path.GetFileName(str1);
string str = "~/DataImage/" + str2;
PhotoFileUpload.SaveAs(MapPath("~/DataImage/" + str2));
 
da = new SqlDataAdapter("insert into Photogallery (Name,Photo) values ('" + NameTextBox.Text + "','" + str + "')", cstring);
da.Fill(ds);
PhotoPanel.Visible = false;
SubmitLabel.Visible = true;
 
}
else
{
ClientScript.RegisterStartupScript(Page.GetType(), "msg", "alert('Please insert image...');", true);
 
}

 

 
}
  Permalink  
v2

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

  Print Answers RSS
0 OriginalGriff 350
1 Jochen Arndt 190
2 Richard MacCutchan 135
3 Sergey Alexandrovich Kryukov 130
4 DamithSL 105
0 OriginalGriff 6,045
1 DamithSL 4,601
2 Maciej Los 4,087
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,310


Advertise | Privacy | Mobile
Web01 | 2.8.141220.1 | Last Updated 15 Oct 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100