Basic4ppc - Windows Mobile Development  

Go Back   Basic4ppc - Windows Mobile Development > Main Category > Questions & Help Needed
Home Register FAQ Members List Search Today's Posts Mark Forums Read

Questions & Help Needed Post any question regarding Basic4ppc.


Problem: fetch and store image to/from database


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 05-12-2008, 02:00 PM
willisgt's Avatar
Senior Member
 
Join Date: Aug 2007
Location: Nacogdoches, Texas USA
Posts: 154
Default Problem: fetch and store image to/from database

I'm trying to (1) store an image in a database, and (2) fetch that image from the database and display it.

The 'fetch and display' routine:

Code:
Sub btnShow_Click

	cmd.CommandText = "SELECT photodata FROM photos"
	reader.Value = cmd.ExecuteReader
	reader.ReadNextRow
	Form1.Image = reader.GetImage(0)

End Sub
produces an error:

'File opened that is not a database file
file is encrypted or is not a database
Continue?'

The 'capture' routine:

Code:
	Dim img
	
	pfn = camera.GetImage( 640, 480, 0, "Form1", "Camera" )

	Msgbox( pfn )

	If pfn <> "" Then

		query = "REPLACE INTO photos ( id, photodata ) VALUES ( 1, " & cmd.FileToBLOB( pfn ) & " ) WHERE ( id = 1 )"

		cmd.CommandText = query
		cmd.ExecuteReader

	End If

End Sub
produce an error:

'File opened that is not a database file
near 'WHERE': syntax
error
Continue?'


The entire program follows:

(the 'camera' object is from dz's camera capture library; 'con' and 'cmd' are SQL library objects)

Code:
Sub Globals

	dbfn = ""

End Sub

Sub App_Start

	Con.New1
	Cmd.New1( "", con.Value )
	dbfn = AppPath & "\photos.s3db"
	Con.Open( "Data Source = " & dbfn )

	reader.New1

	camera.New1


	formHeader.Color = cBlack
	formHeader.FontColor = cWhite
	formHeader.FontSize = 9
	formHeader.Width = form1.Width
	formHeader.Height	= 23
	
	btnShow.Top = 25
	btnCapture.Top = 25


	Form1.Show

End Sub


Sub btnCapture_Click

	Dim img
	
	pfn = camera.GetImage( 640, 480, 0, "Form1", "Camera" )

	Msgbox( pfn )

	If pfn <> "" Then

		query = "REPLACE INTO photos ( id, photodata ) VALUES ( 1, " & cmd.FileToBLOB( pfn ) & " ) WHERE ( id = 1 )"

		cmd.CommandText = query
		cmd.ExecuteReader

	End If

End Sub

Sub btnShow_Click

	cmd.CommandText = "SELECT photodata FROM photos"
	reader.Value = cmd.ExecuteReader
	reader.ReadNextRow
	Form1.Image = reader.GetImage(0)

End Sub

Sub btnClose_Click

	AppClose

End Sub
I'm slowly losing my mind in my old age; does anyone see what I'm doing wrong?


Gary

__________________
PC: Windows XP Pro SP2 / Basic4PPC v6.3
PPC: HTC 8925 (AT&T Tilt) / Windows Mobile 6
Reply With Quote
  #2 (permalink)  
Old 05-13-2008, 06:18 AM
Erel's Avatar
Administrator
 
Join Date: Apr 2007
Posts: 2,806
Default

How did you first create the database?
Reply With Quote
  #3 (permalink)  
Old 05-13-2008, 03:10 PM
willisgt's Avatar
Senior Member
 
Join Date: Aug 2007
Location: Nacogdoches, Texas USA
Posts: 154
Default Problem solved

I first created the database with SQLite Administrator.

However, I found the problem - the syntax of this line:

Code:
query = "REPLACE INTO photos ( id, photodata ) VALUES ( 1, " & cmd.FileToBLOB( pfn ) & " ) WHERE ( id = 1 )"
is completely incorrect. No whereclause was required for this REPLACE INTO.


Gary

__________________
PC: Windows XP Pro SP2 / Basic4PPC v6.3
PPC: HTC 8925 (AT&T Tilt) / Windows Mobile 6
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Image problem with ImageButtons klaus Bug Reports 3 02-15-2008 08:10 AM
Getting ImageButton image from database glook Questions & Help Needed 5 11-16-2007 07:31 AM
Image size problem agraham Bug Reports 4 10-24-2007 05:40 PM
How to convert an Access database to a sqlite database Peter Code Samples & Tips 5 07-24-2007 03:20 PM
Move an image inside an image control Cableguy Questions & Help Needed 5 05-14-2007 07:40 PM


All times are GMT. The time now is 10:14 AM.


Powered by vBulletin® Version 3.6.10
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.1.0