Real Software Forums

The forum for Real Studio and other Real Software products.
[ REAL Software Website | Board Index ]
It is currently Fri Nov 16, 2018 4:39 am
xojo

All times are UTC - 5 hours




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Copy Records Help Needed
PostPosted: Thu Nov 22, 2012 1:14 am 
Offline

Joined: Mon Dec 12, 2011 7:25 pm
Posts: 186
Location: Grand Rapids MI Area
I am creating a database routine in my program that allows a user to copy
chosen records from 1 database to another. A user will load a listbox from
database1 and another listbox from database2 then from database 1 they
choose what records they want copied. I have all that working EXECPT
when one of the tables has more than one item in it. For example a table
that holds pictures has 8 for one record. My routine gets only one of them
and after trying to loop to get the others all I get is 8 of the same picture.

How can I get all pics copied from db1 to db2. ? This has to be by chosen
records and not the whole table. What I have works ok if only one picture
exist for each record but if you have 8 it don't.

This is part of my code. I hope it's enough to get an answer.

if ckbCopyCampgroundPictures.Value And lbxFromDatabase1.CellState(i,0) = CheckBox.CheckedStates.Checked Then
'TABLE = CGPictures
'CGID INTEGER NOT NULL
'Pic1
'ImageID = INTEGER NOT NULL PRIMARY KEY
'PicFileName
'ImageTitle
'Image
Dim nop, NumPics As Integer
// Get the number of pictures in db1 for CGID
Dim sql As String = ("SELECT Count(*) AS NumPics FROM CGPictures WHERE CGID = '" + tmpReadRecord + "'") // tmpReadRecord = old CGID from lbxFromDatabase1
dim rs as RecordSet = tmpDB1.SQLSelect(sql)
NumPics = rs.Field("NumPics").IntegerValue
// Check for errors
if rs=nil then
msgbox "rs = NIL Error....!!!"
return
end
// Create a new database record with all of the CGPictures information
Dim rec as New DatabaseRecord

// Now we get campground CGPictures from db1 and write them to db2
// Read database 1 record
// Find the existing record by searching for the CGID
Dim rs1 As RecordSet = tmpDB1.SQLSelect("SELECT * FROM CGPictures WHERE CGID = '" + tmpReadRecord + "'")

// Write database 2 with the record
For nop = 1 to NumPics

'ImageID = INTEGER NOT NULL PRIMARY KEY
rec.Column("CGID") = tmpNewCGID
rec.Column("Pic1") = rs1.Field("Pic1").StringValue
rec.Column("PicFileName") = rs1.Field("PicFileName").StringValue
rec.Column("ImageTitle") = rs1.Field("ImageTitle").StringValue
rec.Column("Image") = rs1.Field("Image").StringValue

// Insert Record Into table "CGPictures" of the Database
tmpDB2.InsertRecord "CGPictures", rec
// Display Error If One Occurred
if tmpDB2.Error then
App.DisplayDatabaseError true
return
end if
// Commit changes to the database
tmpDB2.Commit

Next

// Uncheck the campground name after the data has been removed
lbxFromDatabase1.CellState(i,0) = CheckBox.CheckedStates.UnChecked

_________________
iMac 27" (2.8GHz Intel Core i5, 16GB RAM, 1TB Drive) OS X Mountain Lion 10.8.3 and Windows 7
Toshiba Laptop Running Windows 7, WinXP SP3 and Windows 8
REAL Studio Enterprise Edition 2012r2.1
http://www.theultimatecampgroundlog.com
Being rewritten for the Mac


Top
 Profile  
Reply with quote  
 Post subject: Re: Copy Records Help Needed
PostPosted: Thu Nov 22, 2012 1:31 am 
Offline

Joined: Fri Jan 06, 2006 3:21 pm
Posts: 12388
Location: Portland, OR USA
You're only pulling one picture from rs1. How are the 8 images stored? All in one record (multiple columns)? Or in multiple records?


Top
 Profile  
Reply with quote  
 Post subject: Re: Copy Records Help Needed
PostPosted: Thu Nov 22, 2012 9:14 am 
Offline

Joined: Mon Dec 12, 2011 7:25 pm
Posts: 186
Location: Grand Rapids MI Area
They are stored as multiple records. CGID is common to all and ImageID is the auto incrementer.

There can be many records in the table for each campground. Each campground has it's own CGID.

_________________
iMac 27" (2.8GHz Intel Core i5, 16GB RAM, 1TB Drive) OS X Mountain Lion 10.8.3 and Windows 7
Toshiba Laptop Running Windows 7, WinXP SP3 and Windows 8
REAL Studio Enterprise Edition 2012r2.1
http://www.theultimatecampgroundlog.com
Being rewritten for the Mac


Top
 Profile  
Reply with quote  
 Post subject: Re: Copy Records Help Needed
PostPosted: Thu Nov 22, 2012 10:17 am 
Offline

Joined: Mon Dec 12, 2011 7:25 pm
Posts: 186
Location: Grand Rapids MI Area
I got it fixed, when I tried to use the
while not rs1.eof
and it did not work because I forgot to use
rs1.MoveNext
at the end.

_________________
iMac 27" (2.8GHz Intel Core i5, 16GB RAM, 1TB Drive) OS X Mountain Lion 10.8.3 and Windows 7
Toshiba Laptop Running Windows 7, WinXP SP3 and Windows 8
REAL Studio Enterprise Edition 2012r2.1
http://www.theultimatecampgroundlog.com
Being rewritten for the Mac


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 5 hours


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group