Save images to sqlite database

Post

Posted
Rating:
#1 (In Topic #1574)
Trainee
rajeevgalaxy is in the usergroup ‘Trainee’
 Dear friends,

am new this forum
I want to know how to save image to sqlite database  from Picturebox.Picture
I tried this method. but it is not stored as a image
If Not IsNull(picChart.Picture) Then
      bb = Byte[].FromString(picChart.Picture.ToString())
      
      cnnFile.Exec("update userdata set indeximage = '" & bb.tostring()  & "'  where dateid = " & dtid)

    Endif
Is there any solution to solve the issue.  I want to save image from picturebox to sqlite and retrive back the data and display in picture box

I request you to kindly help me to solve the issue
Regards
Rajeev
Online now: No Back to the top

Post

Posted
Rating:
#2
Banned
Welcome to the forum.

I do not know much about database access but If it must be utf-8 string then maybe use Base64

Code (gambas)

  1. sImg = Base64(picChart.Picture.ToString())
  2. cnnFile.Exec("update userdata set indeximage = '" & sImg & "' where dateid = " & dtid)
  3.  

To read it back use FromBase64

Code (gambas)

  1. picChart.Picture = Picture.FromString(FromBase64(sDatabaseString))
  2.  
Online now: No Back to the top

Post

Posted
Rating:
#3
Banned
I think we had a similar topic before where it was suggested that it is MUCH BETTER to save the pictures to a disk location and only save the image path in the database.
Images converted to strings can mean a lot of excessive database data making slower reads.
Online now: No Back to the top

Post

Posted
Rating:
#4
Avatar
Regular
thatbruce is in the usergroup ‘Regular’
 Mr Steers is basically right. Storing images as strings in databases most often incurs extra overhead in both storing and retrieving the image at run time.
However 1) if the images tend to be permanent or fairly permanent and a strategy can be built to minimize the loads say for a company logo that is retrieved at program startup or something similar then there is nothing inherently evil about keeping them in the database. Even in the case of say a graph image that is updated once a day, say yesterdays sales totals, then with care the use of database stored images can be relatively efficient and has the extra advantages of dbms backups etc.
2) (as usual rant) sqlite is NOT an efficient database management system. It is absolutely fine for casual or exploratory use but is not suitable for a high use transactional system. PostgreSQL or MariaDB provide much better performance (and features).  But then if you are looking for a SMALL database to store SMALL images (lets say icon sizes) then it is …. ok … but the others are better.
regards
thatbruce

Online now: No Back to the top

Post

Posted
Rating:
#5
Trainee
rajeevgalaxy is in the usergroup ‘Trainee’
 Thank you for your valuable reply.
actualy, the image size is below 100 kb. sqlite is better for my small application.
storing the image in device storage is not practical.

anyway i will try base64 frombase64 func

thank u
Online now: No Back to the top

Post

Posted
Rating:
#6
Trainee
rajeevgalaxy is in the usergroup ‘Trainee’
 Hi

Now its working. and my problem is solved.

thank you Mr. BruceSteers   and   thatbruce
Online now: No Back to the top
1 guest and 0 members have just viewed this.