C# 如何使用ClearScript下的V8更新System.Data datarow中的列?
我正在使用V8ScriptEngineC# 如何使用ClearScript下的V8更新System.Data datarow中的列?,c#,v8,system.data,clearscript,C#,V8,System.data,Clearscript,我正在使用V8ScriptEngine v8 = new V8ScriptEngine(V8ScriptEngineFlags.DisableGlobalMembers); 并将“System.Data”命名空间公开到ClearScript环境中 var htc = new HostTypeCollection(); foreach (var assembly in new string[] { "mscorlib", "System", "System.Core", "System.Data
v8 = new V8ScriptEngine(V8ScriptEngineFlags.DisableGlobalMembers);
并将“System.Data”命名空间公开到ClearScript环境中
var htc = new HostTypeCollection();
foreach (var assembly in new string[] { "mscorlib", "System", "System.Core", "System.Data" })
{
htc.AddAssembly(assembly);
}
...
v8.AddHostObject("CS", htc);
然后,我从Microsoft获取了一个System.Data示例,并尝试将其适应ClearScript/V8环境
const DataTable = CS.System.Data.DataTable;
const DataColumn = CS.System.Data.DataColumn;
const DataRow = CS.System.Data.DataRow;
const table = new DataTable("Product");
// Create a DataColumn and set various properties.
const column = new DataColumn();
column.DataType = CS.System.Type.GetType("System.Decimal");
column.AllowDBNull = false;
column.Caption = "Price";
column.ColumnName = "Price";
column.DefaultValue = 25;
// Add the column to the table.
table.Columns.Add(column);
// Add 10 rows and set values.
let row;
for (let i = 0; i < 10; i++) {
row = table.NewRow();
row["Price"] = i + 1;
// Be sure to add the new row to the
// DataRowCollection.
table.Rows.Add(row);
}
所以问题是,如何更新行中的列?早些时候,我通过在C#端编写一个helper函数来解决这个问题。这仍然是最佳解决方案吗?使用
行.Item.set(“Price”,i+1)而不是行[“Price”]=i+1
。请参阅以获得解释。令人尴尬的是,我认为您以前在字典中告诉过我这一点,但我认为它不适用于DataTable。叹气
Error: Object has no suitable property or field named 'Price'
at Script:24:18 -> row["Price"] = i + 1;