Flex Form Field to be Integer

Hi,

I am pretty new to flex and actionscripting.  I have a flex form with text inputs.  One of them is a number.  I am inserting it into my database(MSSQL) via <mx:RemoteObject> and a coldfusion CFC.

This works great for me on text fields with a field type of varchar.  The problem I have is when inserting the data from the form into a field type of int or integer.

It won't let me insert the new record because I am trying to pass a text field into a number  field.

I know this has to be a simple fix...I just can't figure out how to convert the field into a number before passing it to the CFC.

Thanks for any help.

Tom
<!---Flex Code--->
 
private function clickHandler():void {
				conn.insertRecord(relatedCustomer.text, quoteType.text);
			} 
 
 
 
<!---Coldfusion CFC--->
 
 <cffunction name="insertRecord" access="remote" returntype="void">
	<cfargument name="relatedCustomer" type="numeric" required="true"/>
        <cfargument name="quoteType" type="string" required="true"/>
		
		<cfquery datasource="mydatasource">
			insert		
			into		mytable
						(relatedCustomer, quoteType)
			values		(<cfqueryparam cfsqltype="cf_sql_varchar" value="#relatedCustomer#"/>,
            			<cfqueryparam cfsqltype="cf_sql_varchar" value="#quoteType#"/>)
		</cfquery>
	</cffunction>

Open in new window

tomhwttAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jones911Commented:
cf_sql_varchar  is for text

cf_sql_integer  is for integers


Try change that and you should be good.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
tomhwttAuthor Commented:
Jones911..

Thanks.  I tried that too, it doesn't work.

I am getting closer though.  You have to convert the text field to a number before sending it to the CFC.  I found this code in the Flex Cookbook.  However, I still have a problem.

It converts the field to data type numeric instead of int.  I can get this to work if i change the data type in MSSQL to numeric.  I would like to keep it as int.

Anyone know of  a way to convert the field type to int before sending to the CFC.

Thank You


private function clickHandler():void {
				var myNumber:Number = new Number(relatedCustomer.text)
				conn.insertRecord(myNumber,quoteType.text);
			} 

Open in new window

0
Jones911Commented:
Please show me the query you have for insert.  You don't need to convert if quoteType.text is a number it will work.
0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

tomhwttAuthor Commented:
Jones911,

I am not sure what I was doing.  You are correct.  I had written a fancy variable to convert the string to a number and everything....and it's not needed.  The correct working code is below.

Thank You!
<!---Flex Code--->
 
private function clickHandler():void {			
				conn.insertRecord(relatedCustomer.text,quoteType.text);
}
 
<!---CFC w/ Insert Query--->
 
 <cffunction name="insertRecord" access="remote" returntype="void">
		<cfargument name="relatedCustomer" type="numeric" required="true"/>
        <cfargument name="quoteType" type="string" required="true"/>
		
		<cfquery datasource="mydatasource">
			insert		
			into		myTable
						(relatedCustomer, quoteType)
			values		(<cfqueryparam cfsqltype="cf_sql_integer" value="#relatedCustomer#"/>,
            			<cfqueryparam cfsqltype="cf_sql_varchar" value="#quoteType#"/>)
		</cfquery>
			 

Open in new window

0
Jones911Commented:
Glad its working.

Just for reference if you ever need to convert say 5.776 to an in can do this

var myInt:Int = int(5.667);
0
tomhwttAuthor Commented:
That's exactly what I had done.

var myInt:Int = int(relatedCustomer.text);

But..as you pointed out.  Not needed in this case thanks to:

<cfqueryparam cfsqltype="cf_sql_integer" value="#relatedCustomer#"/>

:)

Thanks again for the help...much appreciated!

Tom
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Adobe Flash

From novice to tech pro — start learning today.