Image From Sqlite Database

How to Retrieve Images from SQLite Database & Show in a ImageView. Can Anyone Tell me the process.
I am Trying but got a error as Picture As Nil. So Please Help me.

What have you tried for pulling the image out of the database?
Please encase code in [code] blocks.

I am retrieving the image from database & use that data in following Code:

Dim pic As Picture
Dim picPath As String=EquipmentListBox.RowTag(EquipmentListBox.ListIndex) // It works fine
Dim picFile As New FolderItem(picPath,FolderItem.PathTypeNative) // its also works fine

pic=Picture.Open(picFile) // Here i Got the error “pic As Nil”
EquipmentCreateWebPage.PictureViewer.Picture=pic

So kindly help me in this problem.

I am retrieving the image from database & use that data in following Code:

Dim pic As Picture
Dim picPath As String=EquipmentListBox.RowTag(EquipmentListBox.ListIndex) // It works fine
Dim picFile As New FolderItem(picPath,FolderItem.PathTypeNative) // its also works fine

pic=Picture.Open(picFile) // Here i Got the error “pic As Nil”
EquipmentCreateWebPage.PictureViewer.Picture=pic

So kindly help me in this problem.

I see you understand how to make things bold with [b] tags, so why did you not use [code] tags?

I don’t see anything in your code that would fetch an image from a SQLite database. I’m not even seeing a SQLite database to begin with. This looks like it loads a picture from a file, that hopefully lives at the path set in a RowTag.

Set a breakpoint and see what picPath and picFile are; just because they do not stop the application from running doesn’t mean they have the value you want. That’s your first step to figuring out why Picture.Open isn’t able to give you a picture.

[b]// It retrieves all details from Equipment Table[/b]
 Dim sql As String
  Dim rs As RecordSet
  Dim db As SQLiteDatabase
  db=DAL.OpenDatabase
  
  sql="SELECT * FROM Equipment"
  rs=db.SQLSelect(sql)
  
  If rs<>Nil Then
    Return rs
  Else
    MsgBox db.ErrorMessage
  End If


[b]// Here i used the above result to show details on a List box[/b]
  Dim bal As New BAL
  Dim rs As RecordSet
  
  rs=bal.GetAllEquipmentBAL
  
  if rs<>Nil Then
    EquipmentListBox.DeleteAllRows
    While NOT rs.EOF
      EquipmentListBox.AddRow(rs.Field("equipmentNMCNo").StringValue)
      EquipmentListBox.Cell(EquipmentListBox.LastIndex,1)=rs.Field("equipmentName").StringValue
      EquipmentListBox.Cell(EquipmentListBox.LastIndex,2)=rs.Field("equipmentREGO").StringValue
      EquipmentListBox.Cell(EquipmentListBox.LastIndex,3)=rs.Field("equipmentSrNoVIN").StringValue
      EquipmentListBox.Cell(EquipmentListBox.LastIndex,4)=rs.Field("equipmentEngineNo").StringValue
      EquipmentListBox.Cell(EquipmentListBox.LastIndex,5)=rs.Field("equipmentInfo").StringValue
      EquipmentListBox.Cell(EquipmentListBox.LastIndex,6)=rs.Field("modelId").StringValue
      EquipmentListBox.Cell(EquipmentListBox.LastIndex,7)=rs.Field("equipmentId").StringValue
      
 [b]     EquipmentListBox.RowTag(EquipmentListBox.LastIndex)=rs.Field("equipmentImage").Value
[/b]      rs.MoveNext
    Wend
  Else
    MsgBox ("Error in display.")
  End If


[b]// Then by clicking a button i do the below function:[/b]
Dim pic As Picture
Dim picPath As String=EquipmentListBox.RowTag(EquipmentListBox.ListIndex) // It works fine
Dim picFile As New FolderItem(picPath,FolderItem.PathTypeNative) // its also works fine

pic=Picture.Open(picFile) // Here i Got the error "pic As Nil"
EquipmentCreateWebPage.PictureViewer.Picture=pic
EquipmentCreateWebPage.Show

Thank you for using the code block, it makes code easier to read.

In your database, what is the type of data for equipmentImage? Is it a BLOB or TEXT?
When you save the image to the database, are you saving the path to the image, or are you saving the actual image data?

The way you currently attempt to load the image suggests you’re saving the path to the image, but from your original question it sounds like you want to save and load the actual image from the database. I think clarification on what’s actually in the database will help both of us proceed.

Picture.Open will only open a folderitem image, so if you’re saving the actual image to the database you’ll have to create the picture from the data instead (using recordset.field().pictureValue)

Again, I recommend setting a breakpoint (or using MsgBox) to find out what picPath and picFile are before you try to use Picture.Open

Thank You. Actually I Stored the Native Path of the image As text in the table of SQlite Database. So kindly tell me the how i get image for display in the image view.

If u have any code regarding this problem then pls share to me. It will be more helpful to me.

If you expect the image to remain in the same location on the computer, you should be able to open it with Picture.Open() Should you find this is the option that works best for you, then you need to check to see if the picture exists before trying to use Picture.Open() I suspect this is where your problem is.

If the image is not going to be in the same location every time, you may consider copying the image to the database. Keep in mind that Xojo is 32 bit currently, and can not take up more than roughly 3.5GB of memory (a large number of images will hit this limit quickly)

To use option two you’re going to have to change how you store the image in the database, and any currently stored path will not be useful, since you’re changing the type. An overhaul like this may present a range of challenges, especially if your application is already live and has users.

When changing to storing the actual image in the database, you need to either change equipmentImage type to BLOB or create a new column that stores the actual image as a BLOB. Creating a new column may present less conflicts with existing databases if your application is already live; but that depends on how you do your error handling.

Once you have a BLOB column, you need to change your saving procedure to save the actual picture data to the database. The best way is to have Xojo handle all the format behind-the-scenes stuff using a SQLitePreparedStatement. Then with the actual picture data saved to the database, you can fetch it using RecordSet.Field(“fieldname”).PictureValue. There’s also some example code on that Language Reference page if you get lost.

If i used BLOB then what format of Image stored in the database table.?

Did you read Xojo Help files:
CreateBlob, SQLiteBlob, SQLiteDatabase.OpenBlob and SQLite Home ?