New topic: Copy Records Help Needed
<http://forums.realsoftware.com/viewtopic.php?t=46016> Page 1 of 1 [ 4 posts ] Previous topic | Next topic Author Message jerryab Post subject: Copy Records Help NeededPosted: Thu Nov 22, 2012 1:14 am Joined: Mon Dec 12, 2011 7:25 pm Posts: 123 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 Lion 10.7.3 and Windows 7 Toshiba Laptop Running Windows 7 & WinXP SP3 REAL Studio Enterprise Edition 2012r1 http://www.theultimatecampgroundlog.com Being rewritten for the Mac Top timhare Post subject: Re: Copy Records Help NeededPosted: Thu Nov 22, 2012 1:31 am Joined: Fri Jan 06, 2006 3:21 pm Posts: 11829 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 jerryab Post subject: Re: Copy Records Help NeededPosted: Thu Nov 22, 2012 9:14 am Joined: Mon Dec 12, 2011 7:25 pm Posts: 123 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 Lion 10.7.3 and Windows 7 Toshiba Laptop Running Windows 7 & WinXP SP3 REAL Studio Enterprise Edition 2012r1 http://www.theultimatecampgroundlog.com Being rewritten for the Mac Top jerryab Post subject: Re: Copy Records Help NeededPosted: Thu Nov 22, 2012 10:17 am Joined: Mon Dec 12, 2011 7:25 pm Posts: 123 Location: Grand Rapids MI Area I got it fixed, when I tried to use the while not rs1.eofand 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 Lion 10.7.3 and Windows 7 Toshiba Laptop Running Windows 7 & WinXP SP3 REAL Studio Enterprise Edition 2012r1 http://www.theultimatecampgroundlog.com Being rewritten for the Mac Top Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending Page 1 of 1 [ 4 posts ] -- Over 1500 classes with 29000 functions in one REALbasic plug-in collection. The Monkeybread Software Realbasic Plugin v9.3. http://www.monkeybreadsoftware.de/realbasic/plugins.shtml [email protected]
