This project has moved. For the latest updates, please go here.

datarow problem

Nov 14, 2016 at 1:59 PM
Hi I must be missing something.
What is wrong with my code

vb.net
Dim engine As New V8ScriptEngine(V8ScriptEngineFlags.EnableDebugging)
engine.AddHostType("Console", GetType(Console))
engine.AddHostType("MessageBox", GetType(MessageBox))
engine.AddHostObject("myRow", ExcelFileDataSet.Tables(0).Rows(0))
Dim jsScript As String = txttest.Text
Try
            engine.Execute(jsScript)
            engine.Script.test
Catch ex As Exception
            MessageBox.Show(ex.Message)
End Try
javascript
function test() {
  MessageBox.Show('a');
  MessageBox.Show(myRow[0].ToString);
}
It first shows me the messagebox with 'a' and afterwards gives me an error
TypeError : Cannot read property 'ToString' of undefined
Coordinator
Nov 14, 2016 at 4:22 PM
Hi wernersita,

What is the actual .NET type of the object you're exposing as "myRow"? If it's System.Data.DataRow, the actual name of the indexer is "Item", and the following syntax should work:
// JavaScript
MessageBox.Show(myRow.Item(0).ToString());
Note that this is a read-only shortcut. Here's the general syntax that ClearScript supports for accessing .NET indexed properties:
// JavaScript
value = obj.Item.get(index1, index2 ...);
obj.Item.set(index1, index2 ..., value);
Note also that ClearScript does support normal JavaScript-style indexing for .NET arrays.

Good luck!