|
-
Jul 21st, 2015, 12:53 AM
#8
Re: Expose C# List<T> to COM Interop and access it from classic asp
If you have already solved the problem, how to do interop,
then all you have to do (at the C#-side of things), to convert
your <List> content (in case it has "multiple Columns") - into
a COM-based DataContainer-Object which will be understood
without problems in the asp-script.
An easy to use COM-DataContainer (even at the C#-end), which
supports multiple Columns, is the ADODB.Recordset.
You will just have to create a freestanding instance of it, and then copy
your <List>-data over, before returning or passing it back to the asp-Script.
A freestanding ADO.Recordset (without any connections to any DB)
can be created as shown below (decide yourself, whether you instantiate
it in the asp-script and pass it as an Object-Param to C#, or if you
create it in C# and just pass it back as a Function-Result.
Code can be pasted into a *.vbs File and tested there...:
Code:
' *.asp-Code:
Dim Rs
Set Rs = CreateEmptyRsWithFourColumns 'create a new ADO-Rs (with 4 Cols)
SimulatesTheCSharpMethodCall Rs '<- pass the (yet empty) Rs-Instance to C#
Rs.MoveFirst
MsgBox Rs(0) 'show the result of the 1st Row and 1st Col
Rs.MoveNext
MsgBox Rs(0) 'show the result of the 2nd Row and 1st Col
'this creation-function could remain in the asp-Script
Function CreateEmptyRsWithFourColumns()
Const Int32 = 3, BSTR = 8, DBL = 5, CUR = 6
Dim Rs
Set Rs = CreateObject("ADODB.Recordset")
'define 4 Columns (of type Int32, BSTR, Double, Currency)
Rs.Fields.Append "fld_Int32", Int32
Rs.Fields.Append "fld_BSTR", BSTR
Rs.Fields.Append "fld_DBL", DBL
Rs.Fields.Append "fld_Cur", CUR
Rs.Open
Set CreateEmptyRsWithFourColumns = Rs
End Function
'this is, what needs to be managed in a copy-over-routine, which gets
'implemented at the C#-end appropriately (replacing this Script-Impl.)
Sub SimulatesTheCSharpMethodCall(Rs)
Rs.AddNew 'adds a 1st Row (or Record) - using FieldName-Strings
Rs("fld_Int32").Value = 1111
Rs("fld_BSTR").Value = "Some String 1"
Rs("fld_DBL").Value = 1111.11111
Rs("fld_Cur").Value = 1111111.11
Rs.AddNew 'add a 2nd Row (or Record) - ZeroBased Indexes work too
Rs(0).Value = 2222
Rs(1).Value = "Some String 2"
Rs(2).Value = 2222.22222
Rs(3).Value = 2222222.22
End Sub
Olaf
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|