Hi all,
 I m trying to return a custom object from .NET to Flex. It s returning Nothing. But I m able to send the same custom object from Flex to .NET.
 
1) The addTitle method, in which I am passing a custom object from Flex to .NET is working fine.
2) In GetTitle method, where I am returning a custom object from .NET to Flex, I am getting undefined. (I have data in the database, for the same inputs, the method is working fine from an .aspx page, so its not that there is no data)
 
Is there something that I am missing out?
MXML
 
<?xml version="1.0" encoding="utf-8"?>
 
<mx:Application xmlns:mx="http://www.macromedia.com/2003/mxml"
    backgroundColor="#FFFFFF"
    initialize="initApp()">
 
    <mx:Script>
        import RemoteTest.Title;
 
        var title:RemoteTest.Title;
 
        function initApp() {
            title=new Title();
                 }
 
        function addTitle() {
            title.au_id=au_id.text;
            title.title_id=title_id.text;
            title.au_ord=Number(au_ord.text);
            title.royaltyper=Number(royaltyper.text);
            srv.addEmployee(title);
        }
 
function getTitle() {
  srv.getEmployee(au_id.text);
  }
 
 function onGetData(event:Object):Void {
   title = event.result;
   title_id.text = title.title_id;
 
 }
     </mx:Script>
 
    <mx:RemoteObject id="srv" source="RemoteTest.Sample">
        <mx:method name="addEmployee"/>
        <mx:method name="getEmployee" result = "onGetData(event)" />
     </mx:RemoteObject>
 
    <mx:Form>
 
        <mx:FormItem label="au_id">
            <mx:TextInput id="au_id"/>
        </mx:FormItem>
        <mx:FormItem label="title_id">
            <mx:TextInput id="title_id"/>
        </mx:FormItem>
        <mx:FormItem label="au_ord">
            <mx:TextInput id="au_ord"/>
        </mx:FormItem>
        <mx:FormItem label="royaltyper">
            <mx:TextInput id="royaltyper"/>
        </mx:FormItem>
   <mx:FormItem>
            <mx:Button label="Add Employee" click="addTitle()"/>
        </mx:FormItem>
 <mx:FormItem>
            <mx:Button label="Get Employee" click="getTitle()"/>
        </mx:FormItem>
  
</mx:Form> 
 
</mx:Application>
ActionScript
 
// ActionScript Document
class RemoteTest.Title {
 
    public var au_id : String;
    public var title_id : String;
    public var au_ord : Number;
    public var royaltyper : Number;
 
    static var registered=
Object.registerClass("RemoteTest.Title", RemoteTest.Title);
}
 
.NET class
 

using System;

using FlashGateway.IO;

using System.Xml;

using System.Data;

using System.Data.SqlClient;

using System.IO;

using System.Text;

using System.Collections;

 

namespace RemoteTest

{

public class Sample

{

private SqlConnection conn;

public void addEmployee(Title employee)

{

conn =new SqlConnection("data source=dt1305-priyanka\\netsdk; database=pubs;uid=sa;pwd=welcome;");

conn.Open();

SqlCommand sqlcomm = new SqlCommand();

sqlcomm.Connection=conn;

sqlcomm.CommandType = CommandType.Text;

sqlcomm.CommandText = "INSERT INTO titleauthor (au_id,title_id,au_ord,royaltyper) VALUES('"+employee.au_id + "','" +employee.title_id +"',"+employee.au_ord +","+employee.royaltyper +")";

sqlcomm.ExecuteNonQuery();

}

 

public Title getEmployee(string au_id)

{

conn =new SqlConnection("data source=dt1305-priyanka\\netsdk; database=pubs;uid=sa;pwd=welcome;");

conn.Open();

SqlCommand sqlcomm = new SqlCommand();

sqlcomm.Connection=conn;

sqlcomm.CommandType = CommandType.Text;

sqlcomm.CommandText = "SELECT * FROM titleauthor WHERE au_id ='" + au_id + "'";

SqlDataReader readerObj = sqlcomm.ExecuteReader();

Title title = new Title();

while (readerObj.Read())

{

title.au_id = au_id;

title.title_id = readerObj.GetString(1);

title.au_ord = (System.Byte)readerObj.GetValue(2);

title.royaltyper = (Int32)readerObj.GetValue(3);

}

return title;

}

}

}

DataObject class in .NET
 

using System;

namespace RemoteTest

{

[Serializable]

public class Title

{

public string au_id;

public string title_id;

public int au_ord;

public int royaltyper;

}

}

Regards
Priyanka

__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com

--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com




SPONSORED LINKS
Computer software testing Macromedia flex Development
Software developer


YAHOO! GROUPS LINKS




Reply via email to