Question : ColdFusion and DOTNET

I have built a DOT NET class library and have a function within that returns a data table.  I can reference the dll within a cfm file,  assign the datatable to a variable and see it's rows with cfdump.  

How can I "bind" the table to a cfgrid with paging etc... ?  I have included the function from the dll for reference.

 
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
Public Function GetDataTable(ByVal sSQL As String) As DataTable
        Dim sConn As String
        Dim dt As DataTable = New DataTable("FOOBAR")

        Try
            sConn = Constants.Config_ConnString("conString_")
            dt = OracleHelper.ExecuteDataTable(sConn, CommandType.Text, sSQL)

        Catch ex As Exception
            Throw New Exception("Exception thrown in GetDataTable", ex)
        End Try
        Return dt

Answer : ColdFusion and DOTNET

... what you could do is create a generic function (no public access) that accepts a SQL string and calls your DLL. Then create a separate function that's accessible to the grid. Inside that function is where you would pass the SQL to your DLL. That would keeps the SQL on the server side.  Plus it's more compartmentalized.  Totally untested, but the general concept is below.  

If you're going to use the same technique on other CFC's, you could probably take advantage of the "extends" attribute of cfcomponent (ie inheritence). So you don't have to duplicate the generic getDataTable function in all of your CFC's.  Let me know if I'm throwing too much at you at once ;)


1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
<cfcomponent>
    <!--- this function runs sql and returns a data table --->
    <cffunction name="getDataTable" access="private" returntype="any" output="false">
         <cfargument name="sql" type="string" required="true">

          <cfset var path = expandPath('./BenefitsOnlineData.dll')>
          <cfset var theDLL = createObject("dotnet", "BenefitsOnlineData.BenefitsOnlineData", path )>
          <cfset var dataTable = theDLL.GetDataTable( arguments.sql )>
          <cfreturn dataTable>
   </cffunction>            

    <!--- get data from an employee table --->
    <cffunction name="getEmployeeData" access="remote" output="false">
         <!--- standard parameters generated by CFGRID --->
         <cfargument name="page" required="yes">
         <cfargument name="pageSize" required="yes">
         <cfargument name="gridsortcolumn" required="yes">
         <cfargument name="gridsortdirection" required="yes">

          <cfset var sql = "SELECT FirstName, LastName FROM EmployeeTable">
          <cfset var dataTable = getDataTable( sql )>
  	  <!--- convert it to a format cfgrid can interpret and return the results --->
         <cfreturn queryconvertforgrid(dataTable, arguments.page, arguments.pagesize ) />
   </cffunction>            

</cfcomponent>    
Random Solutions  
 
programming4us programming4us