
1162
DEVELOPING
COLDFUSION 9 APPLICATIONS
Using Web Elements and External Objects
Las
t
upda
te
d 8/5/2010
ColdFusion Code:
<cfset cflist = netObject.getList()>
<cfloop array="#cflist#" index="item">
<cfoutput>#item#</cfoutput><br>
</cfloop>
<cfif cflist[3]>
<cfoutput>Third element in the list is true</cfoutput>
</cfif>
Using ADO.Net DataTable in ColdFusion
ColdFusion converts System.Data.DataTable objects to ColdFusion query objects, and you can perform all standard
ColdFusion query operations on them. The following example shows this usage:
.Net code:
public DataTable datasetMethod()
{
//conn string
string connectionString = "...";
//connection
using (SqlConnection connection = new SqlConnection(connectionString))
{
SqlCommand cmd = new SqlCommand(@"SELECT * FROM [tblEmployees]", connection);
connection.Open();
SqlDataReader reader = cmd.ExecuteReader();
DataTable dt = new DataTable();
dt.Load(reader);
return dt;
}
}
ColdFusion code:
<cfset query1 = netObject.datasetMethod()>
<cfoutput query="query1">
Query1.CurrentRow = #query1.CurrentRow#<br>
</cfoutput>
Using ColdFusion complex types in .NET input parameters
When a .NET method returns an ArrayList, Hashtable, or DataTable, ColdFusion automatically converts it to a
ColdFusion array, structure, or query, respectively. However ColdFusion does not automatically convert from
ColdFusion data types to these .NET types. (ColdFusion does automatically convert ColdFusion arrays to .Net array
types.) Therefore, you cannot use ColdFusion variables directly as input parameters to .NET object instance methods
that require .NET System.Collection.ArrayList, System.Collection.Hashtable, or System.Data.DataTable types.
Instead create instances of these .NET types and populate them with the required data before you pass them to the
.NET method. For an example of creating and populating a System.Collection.Hashtable object, see the example at the
end of the “Converting data to System.Object type” section.
Содержание COLDFUSION 9
Страница 1: ...Developing Applications ADOBE COLDFUSION 9...