?
Solved

Trying to insert record using flex 3 example

Posted on 2009-03-31
6
Medium Priority
?
605 Views
Last Modified: 2013-12-24
I'm trying to add a new record to the db but nohting gets inserted.  I can populate the datagrid and make a change to an existing record but can't add a new record into the table.  I got this file up on flexcf.com.  Any ideas experts?
mxml:
<?xml version="1.0"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="ro.getData()"  viewSourceURL="srcview/index.html">
	<mx:RemoteObject id="ro" destination="ColdFusion" showBusyCursor="true" source="cfc.crud">
		<mx:method name="getData" result="getDataResult(event)" />
		<mx:method name="saveNewData" result="getDataResult(event)" />
		<mx:method name="saveOldData" result="getDataResult(event)" />
		<mx:method name="deleteData" result="getDataResult(event)" />
	</mx:RemoteObject>
	<mx:Script>
		<![CDATA[
			import mx.collections.ArrayCollection;
			import mx.rpc.events.ResultEvent;
			
			private var isNew:Boolean = true;
			
			public function getDataResult(e:ResultEvent):void{
				dg.dataProvider = e.result as ArrayCollection;
				makeNew();
				
			}
			private function makeNew():void{
				firstNameFld.text = "";
				lastNameFld.text = "";
				officePhoneFld.text = "";
				isNew = true;
			}
			private function save():void{
				if(isNew){
					ro.saveNewData(firstNameFld.text,lastNameFld.text,officePhoneFld.text);
				}else{
					ro.saveOldData(firstNameFld.text,lastNameFld.text,officePhoneFld.text,dg.selectedItem.id);
				}
			}
			private function deleteData():void{
				if(dg.selectedIndex > -1 )ro.deleteData(dg.selectedItem.id);
			}
		]]>
	</mx:Script>
	<mx:DataGrid id="dg" change="isNew = false" width="366">
	</mx:DataGrid>
	<mx:Panel width="424" height="318" layout="absolute">
		<mx:Form top="0" bottom="0" right="0" left="0">
			<mx:FormItem label="First Name" id="firstnameLbl">
				<mx:TextInput id="firstNameFld" text="{dg.selectedItem.firstNameFld}"/>
			</mx:FormItem>
			<mx:FormItem label="Last Name" id="lastnameLbl">
				<mx:TextInput id="lastNameFld" text="{dg.selectedItem.lastNameFld}"/>
			</mx:FormItem>
			<mx:FormItem label="Office Phone" id="officephoneLbl">
				<mx:TextInput id="officePhoneFld" text="{dg.selectedItem.officePhoneFld}"/>
			</mx:FormItem>
		</mx:Form>
	</mx:Panel>
	<mx:Button label="New" click="makeNew()"/>
	<mx:Button label="Save" click="save()"/>
	<mx:Button label="Delete" click="deleteData()" />  
</mx:Application>
 
 
cfc:
<cfcomponent output="false">
	<cffunction name="getData" access="remote" returntype="Query">
		<cfset var local = {} />
		<cfquery name="local.q" datasource="media">
			select		id, firstNameFld, lastNameFld, officePhoneFld
			from		employees
		</cfquery>
		<cfreturn local.q/>
	</cffunction>
	
	<cffunction name="saveNewData" access="remote" returntype="Query">
		<cfargument name="firstNameFld" type="string" required="true"/>
		<cfargument name="lastNameFld" type="string" required="true"/>
		<cfargument name="officePhoneFld" type="string" required="true"/>
		
		<cfquery datasource="media">
			insert		
			into		employees
						( firstNameFld, lastNameFld, officePhoneFld )
			values		( <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.firstNameFld#"/>,
						  <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.lastNameFld#"/>,
						  <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.officePhoneFld#"/> )
		</cfquery>
		<cfreturn getData() />
	</cffunction>
	
	<cffunction name="saveOldData" access="remote" returntype="Query">
		<cfargument name="firstNameFld" type="string" required="true"/>
		<cfargument name="lastNameFld" type="string" required="true"/>
		<cfargument name="officePhoneFld" type="string" required="true"/>
		<cfargument name="id" type="Numeric" required="true" />
		
		<cfquery datasource="media">
			update		employees		
			set			firstNameFld = <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.firstNameFld#" />,
						lastNameFld = <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.lastNameFld#" />,
						officePhoneFld = <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.officePhoneFld#" />
			where		id = <cfqueryparam cfsqltype="cf_sql_integer" value="#arguments.id#" />
		</cfquery>
		<cfreturn getData() />
	</cffunction>
	
	<cffunction name="deleteData" access="remote" returntype="Query">
		<cfargument name="id" type="string" required="true">
		
		<cfquery datasource="media">
			delete
			from		employees
			where		id = <cfqueryparam cfsqltype="cf_sql_integer" value="#arguments.id#" />
		</cfquery>
		<cfreturn getData() />
	</cffunction>
		
</cfcomponent>

Open in new window

0
Comment
Question by:COwebmaster
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
6 Comments
 
LVL 19

Accepted Solution

by:
Gary Benade earned 1000 total points
ID: 24037746
is the id field of your database an autoincrement field?
0
 
LVL 19

Assisted Solution

by:Jones911
Jones911 earned 1000 total points
ID: 24038762
Any errors?
0
 

Author Comment

by:COwebmaster
ID: 24039519
I'm just using a mdb file.  yes, the id field is Autonumber and is a PK.

There is no error.  The fields just become blank.
0
Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

 

Author Comment

by:COwebmaster
ID: 24040019
This is the function on the New button..

private function makeNew():void{
firstNameFld.text = "";
lastNameFld.text = "";
officePhoneFld.text = "";
isNew = true;
}

So isnew is being set to true so shouldn't it call the save() method?..

private function save():void{
if(isNew){
ro.saveNewData(firstNameFld.text,lastNameFld.text,officePhoneFld.text);
}else{
ro.saveOldData(firstNameFld.text,lastNameFld.text,officePhoneFld.text,dg.selectedItem.id);
}
}
0
 

Author Comment

by:COwebmaster
ID: 24040149
actually, i figured it out.  The New button cleared the fields and the Save button, saved the record.
0
 

Author Comment

by:COwebmaster
ID: 24040178
Would you know how I could open a new window to insert new records into the datagrid?  So instead of those buttons on the root, the buttons and the fields would be in a seperate window.
0

Featured Post

Optimum High-Definition Video Viewing and Control

The ATEN VM0404HA 4x4 4K HDMI Matrix Switch supports 4K resolutions of UHD (3840 x 2160) and DCI (4096 x 2160) with refresh rates of 30 Hz (4:4:4) and 60 Hz (4:2:0). It is ideal for applications where the routing of 4K digital signals is required.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A web service (http://en.wikipedia.org/wiki/Web_service) is a software related technology that facilitates machine-to-machine interaction over a network. This article helps beginners in creating and consuming a web service using the ColdFusion Ma…
First things first - Preparation We need all the part for this install and it's much nicer to have them all on hand when you need them so here's what's required. Download Eclipse 3.5 32 bit (I like the Classic flavour) from here. (http://www.e…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Suggested Courses

800 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question