누군가가 이것을 검토하는 데 도움이 될 수 있습니까?이 방법이 VB.Net 코드를 작성하는 올바른 방법입니다. 다음은 데이터베이스에서 값을 가져 오기 위해 작성된 함수입니다.코드 검토 - ExecuteScalar를 사용하여 데이터베이스에서 값을 가져 오는 Vb.Net
Public Function GetIdfromDatabase(ByVal var_Id As IntegerAs String
'Initialize Variables
Dim _GetIdfromDatabase As String
_GetIdfromDatabase = Nothing
Try
_SQLCommand = New SqlCommand("Process", _Conn)
_SQLCommand.CommandText = "Select Name from Process where ID= @Id"
_SQLCommand.Parameters.Add(New SqlParameter("@ID", SqlDbType.Integer))
_SQLCommand.Parameters(0).Value = var_Id
If (_Conn.State <> ConnectionState.Open) Then _Conn.Open()
lvar_GetJobName = _SQLCommand.ExecuteScalar()
Catch ex As Exception
LogError("Error details and description.", ex)
Finally
If Not _SQLCommand Is Nothing Then
_kSQLCommand.Dispose()
End If
If Not _Conn Is Nothing Then
_.Close()
End If
End Try
If _GetIdfromDatabase = Nothing Then
'Log Error here
End If
Return _GetIdfromDatabase
End Function
이 함수는 공용 함수 ExecuteScalarString (cmd를 SqlCommand로) 문자열로 - 문자열 또는 정수 또는 심지어 부울을 반환 할 수 있습니다 - 그럼 세 가지 함수를 작성해야합니까 –
당신은 객체를 반환 할 수 있고 호출 함수에서 변환하거나 3 개의 래퍼 (문자열, int, 부울) 위와 같은 private 메소드를 호출하지만 객체를 반환하고 단순히 래퍼에서 변환을 수행합니다. – PatFromCanada
메신저로 .net 새로운, 내가 위의 지시 사항에 따라 구현하는 데 어려움을 겪고있어 위에서 설명한 [코드 래퍼 메서드] 코드를 제공하는 데 도움이 될 것이라고 –