我有这个类 - CompLoc它从ODBC调用返回两个字段。 我想这样叫这个班。
dim myCompLoc as New CompLoc(company,location)
newCompany = mycompLoc.Company
newLocation = mycompLoc.Location
我的班级。
Private _company As String
Public Property Company() As String
Get
Return _company
End Get
Set(ByVal value As String)
_company = value
End Set
End Property
Private _location As String
Public Property Location() As String
Get
Return _location
End Get
Set(ByVal value As String)
_location = value
End Set
End Property
Public Sub New(ByVal loc As String, ByVal comp As String)
'select company,location from mysqlTable Where location = loc and company = comp'
_company = 'field from ODBC'
_location = 'field from ODBC'
End Sub
我需要传递给ODBC公司和位置,以返回公司和位置(我知道......并不总是在我们手中)。我有这个类,我想从ODBC调用填充。
corp.EmpId = currentRecord(0).ToString
corp.FirstName = currentRecord(1).ToString
corp.LastName = currentRecord(2).ToString
corp.BasePay = Decimal.Parse(currentRecord(3).ToString)
corp.corpCompany = currentRecord(4).ToString
corp.corpLocation = currentRecord(5).ToString
我需要添加到本课程的结尾---
corp.newCompany = myCompLoc.Company
corp.newLocation = myCompLoc.Location
我是否可以有一些指导来正确构建myCompLoc类,以便我可以从corp调用它并使用值接收这两个属性。我可以将它作为数组或其他方法传递,但我想以更好的方式做到这一点。
答案 0 :(得分:0)
以下是我解决这个问题的方法。 corpSQL从属性类继承公司和位置 corp继承自corpMySql
Dim corporation as New Corporation
Dim corp As New corpMySql
Dim newcorp = corp.Getcorp(corp.Company, corp.Location)
corporation.Company = newcorp.NewCompany
corporation.Plant = newcorp.NewLocation
我希望这是有道理的。我能够做到我想要实现的目标,但我认为另一种方式更具流动性。也许使用继承?