Hello,
In VS2003, I tried using an enum and setting it into a field in a
datarow. It seems as if the datatype of the field in the row
determined what went into the field. If the datatype was string, then
the name of the enum item went into the field, but if the datatype was
integer, then the integer value of the enum was stored.
Is this expected behaviour? I couldn't find anything while searching
for answers.
TIA
Barry
'Here is a sample to demonstrate
'option strict and option explicit are on in all files
Public Class testclass2
Public Enum TESTENUM
AA = 1
BB = 2
End Enum
'And other code
End Class
'this is called in a separate form
Private Sub showthis()
Dim dd As System.Data.DataRow
Dim cc As System.Data.DataColumn
Dim tt As System.Data.DataTable
tt = New System.Data.DataTable
cc = New System.Data.DataColumn
With cc
.AllowDBNull = False
.DataType = System.Type.GetType("System.String")
.ColumnName = "string"
End With
tt.Columns.Add(cc)
cc = New System.Data.DataColumn
With cc
.AllowDBNull = False
.DataType = System.Type.GetType("System.Int32")
.ColumnName = "integer"
End With
tt.Columns.Add(cc)
Dim aa() As Object
ReDim aa(1)
aa(0) = "ss"
aa(1) = 100
tt.Rows.Add(aa)
With tt
.Rows(0).Item("string") = testclass2.TESTENUM.AA
System.Windows.Forms.MessageBox.Show(.Rows(0).Item ("string").ToString)
.Rows(0).Item("integer") = testclass2.TESTENUM.AA
System.Windows.Forms.MessageBox.Show(.Rows(0).Item ("integer").ToString)
End With
End Sub
bceggersATcomcastDOTnet