对于此商业登录图层类:
Public Class BankEntity
Private _bankCode As String
Private _bankName As String
Private _bankAddress As String
Public Property bankCode() As String
Get
Return _bankCode
End Get
Set(ByVal value As String)
_bankCode = value
End Set
End Property
Public Property bankName() As String
Get
Return _bankName
End Get
Set(ByVal value As String)
_bankName = value
End Set
End Property
Public Property bankAddress () As String
Get
Return _bankAddress
End Get
Set(ByVal value As String)
_bankAddress = value
End Set
End Property
End Class
这是数据访问层类
Imports System
Imports System.Data
Imports System.Data.SqlClient
Public Class SqlHelper
Private _connStr As String = "Data Source=NEO-PC\SQLEXPRESS;Initial Catalog=dbBank;Integrated Security=True"
Private _conn As SqlConnection
Private _cmd As SqlCommand
Public Function AddNewBank(ByVal BankCode As String, ByVal BankName As String, ByVal BankAddress As String) As Boolean
_conn = New SqlConnection(_connStr)
_cmd = New SqlCommand()
_cmd.Connection = _conn
_cmd.CommandType = CommandType.StoredProcedure
_cmd.CommandText = "AddNewBank"
_cmd.Parameters.AddWithValue("@bankCode", SqlDbType.NVarChar).Value = BankCode
_cmd.Parameters.AddWithValue("@bankName", SqlDbType.NVarChar).Value = BankName
_cmd.Parameters.AddWithValue("@bankAddress", SqlDbType.NVarChar).Value = BankAddress
_conn.Open()
_cmd.ExecuteNonQuery()
_conn.Close()
Return True
End Function
End Class
和此UI类
Dim obj As New sqlHelper
Dim entity As New bankEntity
entity.bankCode = txtBankCode.Text
entity.bankName = txtBankName.Text
entity.bankAddress = txtBankAddress.Text
obj.AddNewBank(entity.bankCode , entity.bankName , entity.bankAddress)
我想只将类(BankEntity)的对象(实体)作为AddNewBank函数的参数。类似的东西:
Dim obj As New sqlHelper
Dim entity As New bankEntity
entity.bankCode = txtBankCode.Text
entity.bankName = txtBankName.Text
entity.bankAddress = txtBankAddress.Text
obj.AddNewBank(entity) ----please have a look here
有可能吗?
答案 0 :(得分:1)
您应该将AddNewBank更改为:
AddNewBank(entity as bankEntity)
然后,您可以轻松地将实体对象传递给您的函数。