Click here to Skip to main content
15,894,343 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hi my friends.
i have picturebox in my program (vb.net).
i want insert picture of picturebox in my database.
how can i do that?
Posted
Updated 4-Jul-14 0:18am
v2

You can save image in folder and image path in database for this

C#
 bool CheckFileType(string fileName)
    {
        string ext = Path.GetExtension(fileName);
        switch (ext.ToLower())
        {
            case ".gif":
                return true;
            case ".jpg":
                return true;
            case ".jpeg":
                return true;
            case ".png":
                return true;
            case ".bmp":
                return true;
            default:
                return false;

        }
    }


protected void btnUpload_Click(object sender, EventArgs e)
    {
        if (fileupload.HasFile)
        {
            if (fileupload.PostedFile.ContentLength < 50000)
            {
                
                if (CheckFileType(fileupload.FileName))
                {

                    String filepath = "FolderName/" + fileupload.FileName;
                    fileupload.SaveAs(MapPath(filepath));

                    qry = "update emp_detail set img='" + filepath.ToString() + "' where emp_id='" + Session["emp_id"].ToString() + "' ";
                    conn.Open();
                    SqlCommand cmd = new SqlCommand(qry, conn);
                    cmd.ExecuteNonQuery();
                    conn.Close();
                }
                else
                {
                    lblmsg.Text = "Only jpg, jpeg, png, gif & bmp Images are Allowed";
                }
            }
            else
            {
                lblmsg.Text = "File size Exceed limit 100KB";
            }
        }
    }
 
Share this answer
 
Refer - Load Images from and Save Images to a Database[^].
Quote:
Sometimes you need to store images in a database instead of as physical files. This sample application will show you how to build a Windows Forms interface that allows you to do the following:
  • Browse for an image on your hard disk
  • Load the selected image into a PictureBox control for viewing
  • Save an image displayed in the PictureBox control to the database
  • Select an image from a ListBox control, and load it from the database
 
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