option strict가 off로 설정된 경우 메서드 오버로딩을 사용하는 것은 나쁜 생각입니까? 아래 코드를 참조하십시오. .NET에는 각 데이터 유형에 대해 별도의 함수가 있습니다. 이 클래스는 Oracle 및 SQL 서버 매개 변수를 처리 할 수 있습니다.Option Strict Off로 함수 오버로딩
Public Class clsParameterValues
'Implements IDisposable
Private paramValues(0) As DbParameter
Public Function AssignParameterValues(ByVal strParameterName As String, ByVal strParameterValue As Long, ByVal intDatabaseType As Integer) As Integer
Dim intArrayBound As Integer
intArrayBound = UBound(paramValues)
'If intArrayBound > 0 Then
If paramValues(0) Is Nothing = False Then
intArrayBound = intArrayBound + 1
ReDim Preserve paramValues(intArrayBound)
End If
If intDatabaseType = 1 Then
paramValues(intArrayBound) = New SqlParameter(strParameterName, strParameterValue)
ElseIf intDatabaseType = 2 Then
paramValues(intArrayBound) = New OracleParameter(strParameterName, strParameterValue)
'paramValues(intArrayBound) = New OracleParameter(":" & strParameterName, OracleType.Int32)
'paramValues(intArrayBound).Value = strParameterValue
End If
paramValues(intArrayBound).DbType = DbType.Int64
Return intArrayBound
End Function
Public Function AssignParameterValues(ByVal strParameterName As String, ByVal strParameterValue As Integer, ByVal intDatabaseType As Integer) As Integer
Dim intArrayBound As Integer
intArrayBound = UBound(paramValues)
'If intArrayBound > 0 Then
If paramValues(0) Is Nothing = False Then
intArrayBound = intArrayBound + 1
ReDim Preserve paramValues(intArrayBound)
End If
If intDatabaseType = 1 Then
paramValues(intArrayBound) = New SqlParameter(strParameterName, strParameterValue)
ElseIf intDatabaseType = 2 Then
paramValues(intArrayBound) = New OracleParameter(strParameterName, strParameterValue)
'paramValues(intArrayBound) = New OracleParameter(":" & strParameterName, OracleType.Int32)
'paramValues(intArrayBound).Value = strParameterValue
End If
paramValues(intArrayBound).DbType = DbType.Int32
Return intArrayBound
End Function
Public Function AssignParameterValues(ByVal strParameterName As String, ByVal strParameterValue As String, ByVal intDatabaseType As Integer) As Integer
Dim intArrayBound As Integer
intArrayBound = UBound(paramValues)
'If intArrayBound > 0 Then
If paramValues(0) Is Nothing = False Then
intArrayBound = intArrayBound + 1
ReDim Preserve paramValues(intArrayBound)
End If
If intDatabaseType = 1 Then
paramValues(intArrayBound) = New SqlParameter(strParameterName, strParameterValue)
ElseIf intDatabaseType = 2 Then
paramValues(intArrayBound) = New OracleParameter(strParameterName, strParameterValue)
'paramValues(intArrayBound) = New OracleParameter(":" & strParameterName, OracleType.Int32)
'paramValues(intArrayBound).Value = strParameterValue
End If
paramValues(intArrayBound).DbType = DbType.String
Return intArrayBound
End Function
Public Function AssignParameterValues(ByVal strParameterName As String, ByVal strParameterValue As Date, ByVal intDatabaseType As Integer) As Integer
Dim intArrayBound As Integer
intArrayBound = UBound(paramValues)
'If intArrayBound > 0 Then
If paramValues(0) Is Nothing = False Then
intArrayBound = intArrayBound + 1
ReDim Preserve paramValues(intArrayBound)
End If
If intDatabaseType = 1 Then
'paramValues(intArrayBound) = New SqlParameter(strParameterName, DateValue(strParameterValue))
paramValues(intArrayBound) = New SqlParameter(strParameterName, strParameterValue)
ElseIf intDatabaseType = 2 Then
paramValues(intArrayBound) = New OracleParameter(strParameterName, strParameterValue)
'paramValues(intArrayBound) = New OracleParameter(":" & strParameterName, OracleType.Int32)
'paramValues(intArrayBound).Value = strParameterValue
End If
paramValues(intArrayBound).DbType = DbType.Date
Return intArrayBound
End Function
Public Function AssignParameterValues(ByVal strParameterName As String, ByVal strParameterValue As Decimal, ByVal intDatabaseType As Integer) As Integer
Dim intArrayBound As Integer
intArrayBound = UBound(paramValues)
'If intArrayBound > 0 Then
If paramValues(0) Is Nothing = False Then
intArrayBound = intArrayBound + 1
ReDim Preserve paramValues(intArrayBound)
End If
If intDatabaseType = 1 Then
paramValues(intArrayBound) = New SqlParameter(strParameterName, strParameterValue)
ElseIf intDatabaseType = 2 Then
paramValues(intArrayBound) = New OracleParameter(strParameterName, strParameterValue)
'paramValues(intArrayBound) = New OracleParameter(":" & strParameterName, OracleType.Int32)
'paramValues(intArrayBound).Value = strParameterValue
End If
paramValues(intArrayBound).DbType = DbType.Decimal
Return intArrayBound
End Function
Public Function AssignParameterValues(ByVal strParameterName As String, ByVal strParameterValue As Boolean, ByVal intDatabaseType As Integer) As Integer
Dim intArrayBound As Integer
intArrayBound = UBound(paramValues)
'If intArrayBound > 0 Then
If paramValues(0) Is Nothing = False Then
intArrayBound = intArrayBound + 1
ReDim Preserve paramValues(intArrayBound)
End If
If intDatabaseType = 1 Then
paramValues(intArrayBound) = New SqlParameter(strParameterName, strParameterValue)
ElseIf intDatabaseType = 2 Then
paramValues(intArrayBound) = New OracleParameter(strParameterName, strParameterValue)
'paramValues(intArrayBound) = New OracleParameter(":" & strParameterName, OracleType.Int32)
'paramValues(intArrayBound).Value = strParameterValue
End If
paramValues(intArrayBound).DbType = DbType.Boolean
Return intArrayBound
End Function
Public Function getParameterValues() As DbParameter()
Return paramValues
End Function
End Class
형식이 올바른지 확인하는 것은 호출자의 책임입니다. 예를 들어, date 유형의 매개 변수를 만들려면 날짜 유형을 전달하십시오. 이게 합리적입니까?