sudhir,
Flex would not understand .net datasets directly, try to return the data as xml formatted string or array of objects(create a class containg the field names) and consume the data in flex in the form of arraycollection/array/xmllist etc
Following are the examples of doing the same in .net
[WebMethod]
public label_data[] fetch_country()
{
SqlConnection SCon = new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings
["ConnectionStringLocal"]);
SCon.Open();
SqlCommand Cmd = new SqlCommand("Fetch_Country", SCon);
Cmd.CommandType = CommandType.StoredProcedure;
SqlDataAdapter da = new SqlDataAdapter(Cmd);
label_data[] cc1;
DataSet ds = new DataSet();
da.Fill(ds);
int k = ds.Tables[0].Rows.Count + 1;
cc1 = new label_data[k];
int i;
int t;
cc1[0] = new label_data();
cc1[0].label = "ALL";
cc1[0].data = "0";
for (i = 0; i < k - 1; i++)
{
cc1[i + 1] = new label_data();
cc1[i + 1].label = (string)ds.Tables[0].Rows[i]["CNTRY_NM"];
cc1[i + 1].data = (string)ds.Tables[0].Rows[i]["CNTRY_KEY"];
}
SCon.Close();
return cc1;
}
or
[WebMethod]
public string GetSalesRevenue(string sCustId, string sFromDate, string sToDate)
{
// Variable Declaration
string sQuery = string.Empty;
string sSBE = string.Empty;
string sRev = string.Empty;
string sTmp = string.Empty;
string sDate =
string.Empty;
int flag = 0;
// Object Declaration
StringBuilder objSBCustXML;
DataSet objDS = null;
// Create a new Instance
objSBCustXML = new StringBuilder();
// Start building the xml
objSBCustXML.Append("<root>");
sFromDate = sFromDate.Substring(0, 2) + sFromDate.Substring(6, 4);
sToDate = sToDate.Substring(0, 2) +
sToDate.Substring(6, 4);
try
{
// Build the Query
sQuery = **some query**
// Exceute the Query to get the DataSet
objDS = this.ExecuteQuery
(sQuery);
// Check for the null condition and number of tables
if (objDS != null && objDS.Tables.Count != 0)
{
// Check for number of rows in the tables
if (objDS.Tables[0].Rows.Count != 0)
{
// Create XML out of the table data
foreach (DataRow objDR in objDS.Tables[0].Rows)
{
if (flag == 0)
{
flag = 1;
continue;
}
// Get the Customer Id and Name
sRev = objDR.ItemArray[2].ToString();
sSBE = objDR.ItemArray[1].ToString();
sDate = objDR.ItemArray[0].ToString();
if (!sSBE.Equals(
string.Empty) && sSBE != "")
{
sTmp = "<sales rev=\"" + sRev + "\" sbe=\"" + sSBE + "\" date=\"" + sDate + "\"/>";
objSBCustXML.Append(sTmp);
}
}
}
}
}
catch (Exception objExp)
{
// Do nothing for now
}
finally
{
objDS = null;
}
objSBCustXML.Append("</root>");
return objSBCustXML.ToString();
}
Flex code:-
private function csa_onResult(e:ResultEvent):void
{
var st:String=e.result as String;
var xml1:XMLList=new XMLList(st); //with root
var st1:String=st.slice(6,(st.length-7));//string without root tag
var xml2:XMLList=new XMLList(st1);//xml without root tag
//other logic
}
-saurabh narula
http://saurabhnarula.wordpress.com