[英]How to set fields in DataRow object
我已將舊代碼從 vb 遷移到 c#。 以下遷移的代碼行引發錯誤:
using System.Data;
..
..
DataRow targetDataRow = targetDataTable.NewRow();
targetDataRow.SetField("DateValue", calendarRow.DateValue.ToShortDateString);
錯誤:
=Error CS1061 'DataRow' does not contain a definition for 'SetField' and no accessible extension method 'SetField' accepting a first argument of type 'DataRow' could be found (are you missing a using directive or an assembly reference?)
我知道我可以像這樣使用它:
targetDataRow["DateValue"] = calendarRow.DateValue.ToShortDateString);
但是,這是將值設置為 DataRow object 中的字段的最佳做法嗎?
以下遷移的代碼行引發錯誤:
Error CS1061 'DataRow' does not contain a definition for 'SetField' and no accessible extension method 'SetField' accepting a first argument of type 'DataRow' could be found (are you missing a using directive or an assembly reference?)
此錯誤是因為您嘗試使用項目中未引用的DataRowExtension.SetField 方法。
要添加它,您可以使用 PM 控制台進行添加:
Install-Package System.Data.DataSetExtensions -Version 4.5.0-preview1-26216-02
這是將值設置為 DataRow object 中的字段的最佳做法嗎
在這種情況下,設置或調用方法都沒有關系。 在引擎蓋下SetField正在做完全相同的事情,僅此而已。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.