|
-
Jul 6th, 2015, 07:04 AM
#1
Thread Starter
Hyperactive Member
Expose C# List<T> to COM Interop and access it from classic asp
Hi,
I have developed a C# COM Component which will return a List<classname> as result. But not able to read this from classic asp. Please help me to sort out this issue.
-
Jul 6th, 2015, 09:43 AM
#2
Re: Expose C# List<T> to COM Interop and access it from classic asp
Lists don't exist in classic ASP... you'll either need to return it as an array, or a collection... you could try returning it as a List, and then declare the variable on the ASP side as a collection and see if that works... but something tells me it's not going to.
-tg
-
Jul 6th, 2015, 09:48 AM
#3
Thread Starter
Hyperactive Member
Re: Expose C# List<T> to COM Interop and access it from classic asp
 Originally Posted by techgnome
Lists don't exist in classic ASP... you'll either need to return it as an array, or a collection... you could try returning it as a List, and then declare the variable on the ASP side as a collection and see if that works... but something tells me it's not going to.
-tg
Hi,
Thank you for reply.
I have tried like this http://stackoverflow.com/questions/5...097474#5097474
But in this they are sending only one dimensional array but mine multi dimensional array.
Thank you.
-
Jul 6th, 2015, 09:58 AM
#4
Re: Expose C# List<T> to COM Interop and access it from classic asp
Huh? is it a List<> or a multi-dimensional array? It can't be both. Are you returning a List<> with another List<> in it? Bottom line, VBScript in ASP cannot handle a List<> whether it's the main object returned or a property of another object or the property of a property of an object... it needs to be an array... if you look at the example at the link, you'll see that's exactly what they are doing... casting the list .ToArray and returning that result.
-tg
-
Jul 6th, 2015, 12:18 PM
#5
Thread Starter
Hyperactive Member
Re: Expose C# List<T> to COM Interop and access it from classic asp
Thanks for the quick reply.
In .net it is a list, but I have converted that list to an array.
Now I want to send this array to classic asp via COM.
Please help me in that.
-
Jul 6th, 2015, 01:24 PM
#6
Re: Expose C# List<T> to COM Interop and access it from classic asp
-
Jul 7th, 2015, 12:52 AM
#7
Thread Starter
Hyperactive Member
Re: Expose C# List<T> to COM Interop and access it from classic asp
Hi,
Thank you for the reply.
That is my another post for the COM interop issue and I have resolved it.
But this is for converting C# List to Classic asp. Have to pass via COM.
-
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
|