Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/339.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 访问bindingsource列值_C#_Bindingsource - Fatal编程技术网

C# 访问bindingsource列值

C# 访问bindingsource列值,c#,bindingsource,C#,Bindingsource,如何用代码更新绑定源中的列值 我正在尝试类似的东西: CustomersBindingSource.AddNew(); CustomersBindingSource.Current["CustomerID"] = Guid.NewGuid(); 此代码当前错误声明:“无法将[]索引应用于'object'类型的表达式。” 非常感谢您对重新撰写此文章的任何帮助 BindingSource的属性在返回的内容中非常通用:type object。对象未定义索引器,因此[]无法工作。您需要做的是将当前属性

如何用代码更新绑定源中的列值

我正在尝试类似的东西:

CustomersBindingSource.AddNew();
CustomersBindingSource.Current["CustomerID"] = Guid.NewGuid();
此代码当前错误声明:“无法将[]索引应用于'object'类型的表达式。”

非常感谢您对重新撰写此文章的任何帮助

BindingSource的属性在返回的内容中非常通用:type object。对象未定义索引器,因此[]无法工作。您需要做的是将当前属性强制转换为它真正的类型(更具体)

例如,如果Current实际上是DataRowView,则可以编写:

DataRowView current = (DataRowView)CustomersBindingSource.Current;
current["CustomerID"] = Guid.NewGuid();    
希望这有帮助,