8 Replies - 9949 Views - Last Post: 17 January 2013 - 06:01 AM Rate Topic: -----

#1 Jovel Mark  Icon User is offline

  • D.I.C Head

Reputation: -3
  • View blog
  • Posts: 81
  • Joined: 22-November 11

Save and Retrieve images in Database

Posted 15 January 2013 - 09:23 PM

HEllo Guys, I need your help, i want to save picture in my database, then after i save picture in database, i want to show it in PICTURE toolbox in VB 6.0,

Guys is this correct how to save?
dim str as string
str = "INSERT INTO tblenroll values('" & Me.txtno.Text & "','" & txtlname.Text & "', '" & txtfname.Text & "','" & txtmi.Text & "', " & txtage.Text & ", '" & cmbgender.Text & "', '" & cmbcourse.Text & "', " & cmbyrlevel.Text & ", '" & cmbstatus.Text & "', '" & cmbreligion.Text & "', '" & cmbcitizenship.Text & "', '" & birthday.Value & "', '" & txtplace.Text & "', '" & Image1.Picture & "')"
acd.Execute str 


and I donot know how to query it, please help me guys, thanks in advance, i will appreciate it.

Is This A Good Question/Topic? 0
  • +

Replies To: Save and Retrieve images in Database

#2 Martyr2  Icon User is offline

  • Programming Theoretician
  • member icon

Reputation: 4364
  • View blog
  • Posts: 12,182
  • Joined: 18-April 07

Re: Save and Retrieve images in Database

Posted 15 January 2013 - 10:17 PM

First you can start off by telling us which type of database you are working with. Secondly, we can tell you that you should NOT directly store images into a database.... and yes even if it allows you to. Typically you store the path to the image file in the database and then you pull the path back up and use it to load the image into your picturebox.

:)
Was This Post Helpful? 1
  • +
  • -

#3 Jovel Mark  Icon User is offline

  • D.I.C Head

Reputation: -3
  • View blog
  • Posts: 81
  • Joined: 22-November 11

Re: Save and Retrieve images in Database

Posted 15 January 2013 - 10:30 PM

View PostMartyr2, on 15 January 2013 - 10:17 PM, said:

First you can start off by telling us which type of database you are working with. Secondly, we can tell you that you should NOT directly store images into a database.... and yes even if it allows you to. Typically you store the path to the image file in the database and then you pull the path back up and use it to load the image into your picturebox.

:)/>

i am using MS Access 2003, Can you show me sample code for what is the correct code for store the path to the image file in the database. Thanks,
Was This Post Helpful? 0
  • +
  • -

#4 Martyr2  Icon User is offline

  • Programming Theoretician
  • member icon

Reputation: 4364
  • View blog
  • Posts: 12,182
  • Joined: 18-April 07

Re: Save and Retrieve images in Database

Posted 15 January 2013 - 10:47 PM

Simple, declare the field type in the database to be "text" and store "c:\somepathonystem\yourimage.png". Then make sure yourimage.png is in that directory. Then when you query you can read that path out and use it to set your picturebox using LoadPicture(thepath).

Now you can also use relative paths when storing it in the database so that it reads like "yourimage.png" in the database and then use something like LoadPicture(App.Path & "\" & rs("thepicture")).

But that is getting a little complex here. Just know that it is a text field that simply holds a string representing the path to the image you want to later retrieve from the file system.

:)
Was This Post Helpful? 0
  • +
  • -

#5 Jovel Mark  Icon User is offline

  • D.I.C Head

Reputation: -3
  • View blog
  • Posts: 81
  • Joined: 22-November 11

Re: Save and Retrieve images in Database

Posted 15 January 2013 - 11:01 PM

View PostMartyr2, on 15 January 2013 - 10:47 PM, said:

Simple, declare the field type in the database to be "text" and store "c:\somepathonystem\yourimage.png". Then make sure yourimage.png is in that directory. Then when you query you can read that path out and use it to set your picturebox using LoadPicture(thepath).

Now you can also use relative paths when storing it in the database so that it reads like "yourimage.png" in the database and then use something like LoadPicture(App.Path & "\" & rs("thepicture")).

But that is getting a little complex here. Just know that it is a text field that simply holds a string representing the path to the image you want to later retrieve from the file system.

:)/>

Sir Martyr i am Using Common Dialog to find images. and this is my code,
CommonDialog1.FileName = ""
CommonDialog1.Filter = "(*.bmp;*.ico;*.gif;*.jpg)/*.bmp;*.ico;*.gif;*.jpg"
CommonDialog1.ShowOpen
    
    If Len(CommonDialog1.FileName) <> 0 Then
        pathpic = CommonDialog1.FileName
        Image1.Picture = LoadPicture(CommonDialog1.FileName)
    End If 

but my problem when i use it how to save it,. can you help me?
Was This Post Helpful? 0
  • +
  • -

#6 Neku  Icon User is offline

  • D.I.C Regular

Reputation: 20
  • View blog
  • Posts: 268
  • Joined: 21-May 09

Re: Save and Retrieve images in Database

Posted 16 January 2013 - 03:40 PM

you want to save the picture itself or the database file?
Was This Post Helpful? 0
  • +
  • -

#7 Jovel Mark  Icon User is offline

  • D.I.C Head

Reputation: -3
  • View blog
  • Posts: 81
  • Joined: 22-November 11

Re: Save and Retrieve images in Database

Posted 16 January 2013 - 11:59 PM

View PostNeku, on 16 January 2013 - 03:40 PM, said:

you want to save the picture itself or the database file?

hello sir Neku, Yes I want to save Profile of Student with picture in the ms access database. then i am using common dialog to find images , after that i want to save it directly into database, then when i search the name of student, its directly show their profile in my VB 6.0 toolbox like text, and also i want to show their picture in picture toolbox of vb 6.0 sir can you help me? thanks in advance. is this correct how to save or insert data in database with picture?
dim str as string
str = "INSERT INTO tblenroll values('" & Me.txtno.Text & "','" & txtlname.Text & "', '" & txtfname.Text & "','" & txtmi.Text & "', " & txtage.Text & ", '" & cmbgender.Text & "', '" & cmbcourse.Text & "', " & cmbyrlevel.Text & ", '" & cmbstatus.Text & "', '" & cmbreligion.Text & "', '" & cmbcitizenship.Text & "', '" & birthday.Value & "', '" & txtplace.Text & "', '" & Image1.Picture & "')"
acd.Execute str 

Was This Post Helpful? 0
  • +
  • -

#8 Neku  Icon User is offline

  • D.I.C Regular

Reputation: 20
  • View blog
  • Posts: 268
  • Joined: 21-May 09

Re: Save and Retrieve images in Database

Posted 17 January 2013 - 05:39 AM

well i only made my own costume text based database but as it was told here before dont save the picture itself into the database file.
the data base file should only hold the file path of the picture so when you load it the picture will be loaded to the right control.

now it seems you already have the code you need to look for a picture so when saving the file you need to save the Image1.Picture property.
Was This Post Helpful? 0
  • +
  • -

#9 andrewsw  Icon User is online

  • It's just been revoked!
  • member icon

Reputation: 3642
  • View blog
  • Posts: 12,620
  • Joined: 12-December 12

Re: Save and Retrieve images in Database

Posted 17 January 2013 - 06:01 AM

There is a tutorial here.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1