我正在使用 oop 概念开发应用程序。我有一个具有 2 个属性的类,并具有 Get 和 Set 方法,即 WorkItemNumber 和 Description。
在客户端,我有一个列表框,用于根据它们的描述填充工作项。这是我在类中编写的代码,用于从数据库中读取项目。
Public Sub LoadWorkItem()
' Load the data.
' Select records.
Dim oWorkItem As WorkItem = New WorkItem()
Dim conn As New OleDbConnection
Dim data_reader As OleDbDataReader
conn = oWorkItem.GetDbConnection()
Dim cmd As New OleDbCommand("SELECT * FROM work_item ORDER BY [work item number]", conn)
data_reader = cmd.ExecuteReader()
'ListBox1.Items.Clear()
If data_reader.HasRows = True Then
Do While data_reader.Read()
WorkItemNumber = data_reader.Item("work item number")
Description = data_reader.Item("description")
Loop
End If
data_reader.Close()
data_reader = Nothing
cmd.Dispose()
cmd = Nothing
conn.Close()
conn.Dispose()
End Sub
我如何使用代码填充列表框,如果代码有任何改进,请告诉我。谢谢