Quantcast
Channel: ClearScript
Viewing all articles
Browse latest Browse all 2297

New Post: for each item in collection loop does not work for datatable

$
0
0
Hello shripaldalal,

Can this work in V8 ? I don't mind using Count and Item properties for iteration but I would prefer this more.

JavaScript's for/in statement does work, but it doesn't do what you think it does. It iterates through the names of an object's properties. For a .NET DataRowCollection, it returns "Add", "Clear", "Contains", etc. It returns strings, and since you can't assign a string to a .NET property of type DataRow, you get "Invalid field assignment".

In general, script constructs such as JavaScript's for/in and VBScript's for each were designed for script object models that are very different from .NET's. ClearScript aims to provide full access to .NET objects and types; it doesn't (and often can't) automatically create ideal APIs for specific script languages.

That said, it might be possible to expose .NET collections to VBScript's for each. We're looking into it.

If I dont declare the variables it gives error as: Object not a collection at Microsoft.ClearScript.ScriptEngine

"Object not a collection" is a VBScript-specific error message. Are you sure you're seeing it when using JScript?

Thanks!

Viewing all articles
Browse latest Browse all 2297

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>