Link to home
Start Free TrialLog in
Avatar of Murray Brown
Murray BrownFlag for United Kingdom of Great Britain and Northern Ireland

asked on

VB.net SQL make sure only single value returned

Hi. I am using the following code to pull a single result from a SQL table.
I need a way to check if the result returns more than one value first.
Is there a way to build that into this code? If not what code would I need
to run first to see if there is a single value returned for this SQL statement

                Dim connection As New SqlConnection(oConnectionString)
                Dim cmd As New SqlCommand(sSQL, connection)
                connection.Open()
                oResult = cmd.ExecuteScalar.ToString
                If IsDBNull(oResult) = True Then
                    Get_Value = "Null"
                Else
                    Get_Value = oResult
                End If
                connection.Close()
ASKER CERTIFIED SOLUTION
Avatar of AndyAinscow
AndyAinscow
Flag of Switzerland 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
Avatar of Murray Brown

ASKER

Thanks very much