我正在加载一个包含 7 个对象的列表,但是这些对象被添加的最后一个对象“覆盖”。有 7 个对象被创建(Exec、Mgr、Position...等)第一个“Exec”被正确添加到列表中,但是创建的每个新 OrgShape 都会覆盖之前添加到列表中的所有 OrgShape . 我知道我错过了一些简单的东西......
Public Shared Function GetOrgShapeData() As List(Of OrgShape)
Dim OgrShapeList As New List(Of OrgShape)
Dim conn As OleDbConnection = HR_DB.GetConnection
Dim strSQL As String
strSQL = "SELECT * FROM VisioShapeDim"
Dim selectCommand As New OleDbCommand(strSQL, conn)
Try
conn.Open()
Dim reader As OleDbDataReader = selectCommand.ExecuteReader
Dim orgshape As OrgShape
Do While reader.Read
orgshape = New OrgShape
orgshape.ShapeName = reader("ShapeName")
orgshape.ShapeWidth = reader("ShapeWidth")
orgshape.ShapeHeight = reader("ShapeHeight")
OgrShapeList.Add(orgshape)
orgshape = Nothing
Loop
reader.Close()
Catch ex As OleDbException
Throw ex
Finally
conn.Close()
End Try
Return OgrShapeList
End Function
'**添加了 OrgShape 类
Public Class OrgShape
Private Shared m_ShapeName As String
Private Shared m_ShapeWidth As Double
Private Shared m_ShapeHeight As Double
Public Sub New()
End Sub
Public Shared Property ShapeName() As String
Get
Return m_ShapeName
End Get
Set(ByVal value As String)
m_ShapeName = value
End Set
End Property
Public Shared Property ShapeWidth() As Double
Get
Return m_ShapeWidth
End Get
Set(ByVal value As Double)
m_ShapeWidth = value
End Set
End Property
Public Shared Property ShapeHeight() As Double
Get
Return m_ShapeHeight
End Get
Set(ByVal value As Double)
m_ShapeHeight = value
End Set
End Property
End Class