0

7 つのオブジェクトを含むリストを読み込んでいますが、オブジェクトは最後に追加されたオブジェクトで「上書き」されます。作成される 7 つのオブジェクト (Exec、Mgr、Position... など) があります。最初の「Exec」はリストに正しく追加されますが、作成される新しい OrgShape ごとに、以前にリストに追加されたすべての OrgShapes が上書きされます。 . 私は何か簡単なものを見逃していることを知っています...

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
4

3 に答える 3

1

Sharedインスタンスを探しているので、プロパティと変数からキーワードを削除してみてください。

Public Class OrgShape
  Private m_ShapeName As String
  Private m_ShapeWidth As Double
  Private m_ShapeHeight As Double

  Public Property ShapeName() As String
    Get
      Return m_ShapeName
    End Get
    Set(ByVal value As String)
      m_ShapeName = value
    End Set
  End Property

共有 (Visual Basic)を参照してください。

于 2013-01-18T16:46:05.400 に答える
0

次の行を削除する必要があります

orgshape = Nothing

毎回オブジェクトを消去しています。

.NET オブジェクトはreference型であることを忘れないでください。

質問の編集に基づいて編集します。また、インスタンス データに共有フィールドとプロパティを使用することもできません。

于 2013-01-18T16:41:42.013 に答える
0

ループで使用Dim orgshape As new OrgShapeして削除orgshape = New OrgShapeし、orgshape = Nothing

于 2013-01-18T16:46:05.360 に答える