searching function

using VB.NET 05, I have implemented a form and some controls. I have some difficulties with the following function:
the class "DataValidator"
 Public Shared Function InvoiceExists(ByVal search As frmSearch) As Boolean
        Dim connection As OleDbConnection = GetConnection()
        Dim countStatement As String
        countStatement = "SELECT Count(BillsID) FROM Invoices WHERE studentID =?"
        Dim countCommand As New OleDbCommand(countStatement, connection)
        countCommand.Parameters.AddWithValue("?", search.txtStudentID.Text.Trim)
        Try
            connection.Open()
            Dim searchCount As Integer = countCommand.ExecuteNonQuery
            If searchCount > 0 Then
                Return True
            Else
                Return False
            End If
        Catch ex As Exception
            Return False
        Finally
            connection.Close()
        End Try
    End Function

Even though, I enter an existing billsID, I still get a non existence message, from the following class "frmInvoice"
if DataValidator.InvoiceExists then
        frmBills.Show
else
       messageBox.show("hughbkihnnjnnkk, "non existence")
end if

can you help me.
Arnaud241Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

PlatoConsultantCommented:
For UPDATE, INSERT, and DELETE statements, the return value is the number of rows affected by the command. For all other types of statements, the return value is -1.

Use Execute Scaler Mathod to get a single value

Executes the query and returns the first column of the first row in the result set returned by the query. All other columns and rows are ignored.

Dim searchCount As Integer = countCommand.ExecuteScaler
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
PlatoConsultantCommented:
Exexute Non Query Method  returns For UPDATE, INSERT, and DELETE statements, the return value is the number of rows affected by the command. For all other types of statements, the return value is -1.


check detail Documentation in MSDN

Just Replace Execute Non Query With the Execute Scaler Method
0
Jorge PaulinoIT Pro/DeveloperCommented:
Try this way

Public Shared Function InvoiceExists(ByVal search As frmSearch) As Boolean
        Dim connection As OleDbConnection = GetConnection()
        Dim countStatement As String
        countStatement = "SELECT Count(BillsID) As Total FROM Invoices WHERE studentID = '" & search.txtStudentID.Text.Trim & "'"
        Dim countCommand As New OleDbCommand(countStatement, connection)
        Try
            connection.Open()
            Dim searchCount As Integer = countCommand.ExecuteNonQuery()
            If searchCount > 0 Then
                Return True
            Else
                Return False
            End If
        Catch ex As Exception
            Return False
        Finally
            connection.Close()
        End Try
    End Function
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.