Welcome To The Home Of The Visual FoxPro Experts  
home. signup. forum. archives. search. google. articles. downloads. faq. members. weblogs. file info. rss.
 From: Stewart Chew
  Where is Stewart Chew?
 
 Malaysia
 Stewart Chew
 Tags
Subject: Insert Records
Thread ID: 143253 Message ID: 143253 # Views: 6 # Ratings: 0
Version: Visual FoxPro 9 Category: Databases, Tables and SQL Server
Date: Monday, August 27, 2007 5:52:10 AM         
   


Dear All,

I've encounter to insert a records into MySql Database. First i use SELECT command to select records i needed, then i use INSERT command to insert all the records from my query into MySql Database. My problem is i've 3 records in my query, when i use insert command only 1 record is inserted. Please refer to my command below;

DO CASE
	CASE THIS.Caption = [Insert]
		
		mUnitCost = THISFORM.cbUnitPrice.Value
		DO WHILE .T.
		LOCATE FOR cSticker.unit_cost = 0 AND upd = 1
		IF FOUND()
			IF MESSAGEBOX('Save',292,'Are you sure?') = 6

				UPDATE cSticker SET unit_cost = mUnitCost, dt_upd = DATETIME(), upd_by = pUserid, unit_cost = mUnitCost;
					WHERE upd = 1
				
				SELECT part_code, part_desc, width, length, height, part_uos, db_part, name, ttl_ups, c_front, c_back, u_sheet, dt_upd, upd_by, unit_cost;
					FROM cSticker WHERE upd = 1;
					INTO CURSOR crSticker NOFILTER
					
				TEXT TO lcSql NOSHOW PRETEXT 15 TEXTMERGE
					INSERT INTO s_partcode(part_code, part_desc, width, length, height, part_uos, db_part, name, ttl_ups, c_front, c_back, u_sheet, dt_upd, upd_by, unit_cost)
						VALUES (?crSticker.part_code, ?crSticker.part_desc, ?crSticker.width, ?crSticker.length, ?crSticker.height, ?crSticker.part_uos,
						?crSticker.db_part, ?crSticker.name, ?crSticker.ttl_ups, ?crSticker.c_front, ?crSticker.c_back, ?crSticker.u_sheet, ?crSticker.dt_upd,
						?crSticker.upd_by, ?crSticker.unit_cost)
				ENDTEXT

				IF SQLPREPARE(oConn, lcSql) < 0
					AERROR(laError)
					MESSAGEBOX(laError[1,2])
				ENDIF

				IF SQLEXEC(oConn) < 0
				   AERROR(laError)
				   MessageBox(laError[1,2])
				   EXIT
				ENDIF
			ENDIF
			EXIT
		ELSE
			WAIT WINDOWS [Please Select The Right Selection!!]
			EXIT
		ENDIF
		ENDDO
	
		THIS.Caption = [Add]
		THISFORM.Command2.Caption = [Edit]
		THISFORM.Command3.Caption = [Update Batch]
		THISFORM.cbUnitPrice.Visible = .F.

	CASE THIS.Caption = [Add]
		
		DO FORM m_saddpart_cat.scx
		
ENDCASE


Regards,

Stewart Chew

ENTIRE THREAD

Insert Records Posted by Stewart Chew @ 8/27/2007 5:52:10 AM
RE: Insert Records Posted by Vladimir Zhuravlev @ 8/27/2007 6:29:45 AM
RE: Insert Records Posted by Stewart Chew @ 8/27/2007 7:26:44 AM