Link to home
Start Free TrialLog in
Avatar of RIAS
RIASFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Correct code

Hello,

Is there a better way of writing this:
 Public Function FindValue(ByVal tablename As String, ByVal StrCol1 As String, ByVal StrCol2 As String, ByVal StrValue As String)
        'get max value in the column
        MedicalSQL.OpenConnection()
        Dim SQLobj As New SqlCommand("al_FrmCol")
        Dim StrReturnValue As Object = String.Empty
        Try
            SQLobj.Parameters.AddWithValue("@tableName", tablename)
            SQLobj.Parameters.AddWithValue("@ColumnName1", StrCol1)
            SQLobj.Parameters.AddWithValue("@ColumnName2", StrCol2)
            SQLobj.Parameters.AddWithValue("@Value", StrValue)
            SQLobj.CommandType = CommandType.StoredProcedure
            SQLobj.Connection = MedicalSQL.GetConnection
            If SQLobj.ExecuteScalar Is DBNull.Value = False Then
                StrReturnValue = SQLobj.ExecuteScalar
            End If
            MedicalSQL.CloseConnection()
            Return StrReturnValue
        Catch ex As Exception
            MessageBox.Show(ex.ToString)
        End Try
    End Function

Cheers
SOLUTION
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of RIAS

ASKER

Cheers!