0
我遇到了處理由我自己定義的對象(位置)的DataTable的問題。 對象存儲一些數據並覆蓋ToString,Equals和GetHashCode。此外,它爲==和!=提供了靜態運算符。DataTable不合並用戶定義的對象
只要存儲此對象的列不是關鍵列,DataTable就能正常工作。將其設置爲PrimaryKey並將其他表合併到其中會失敗,因爲內容不會相同。 (提供datagridview和DataTable本身查找合併後違反密鑰的數據。)
附加您會發現一些手動比較合併後的數據。
有沒有人知道如何處理?
最好的問候,的Tilo
this.data.Rows[1][5]==this.data.Rows[0][5]
false
(Position)this.data.Rows[1][5]==(Position)this.data.Rows[0][5]
true
this.data.Rows[1][5].Equals(this.data.Rows[0][5])
true
this.data.Rows[1][5].GetHashCode()
-461267399
this.data.Rows[0][5].GetHashCode()
-461267399
this.data.Columns[5]
{PositionX}
base {System.ComponentModel.MarshalByValueComponent}: {PositionX}
AllowDBNull: false
AutoIncrement: false
AutoIncrementSeed: 0
AutoIncrementStep: 1
Caption: "PositionX"
ColumnMapping: Element
ColumnName: "PositionX"
DataType: {Name = "Position" FullName = "TiloW.Parameter.Position"}
DateTimeMode: UnspecifiedLocal
DefaultValue: {}
Expression: ""
ExtendedProperties: Count = 1
MaxLength: -1
Namespace: ""
Ordinal: 5
Prefix: ""
ReadOnly: false
Table: {}
Unique: false
歡迎來到SO。請求您請分享代碼。 – Luv 2012-12-21 05:00:13