You don't need a DataReader for this, take a look at this example:
Edit - I see that you actually need the username and PC name values. I'm going to eat and come back to this if no one's answered.Code:Private Function RowCount(ByVal username As String, ByVal pcName As String) As Integer 'Declare the object to return Dim count As Integer = -1 'Declare the connection object Dim con As OleDbConnection 'Wrap code in Try/Catch Try 'Set the connection object to a new instance 'TODO: Change "My Connection String Here" with a valid connection string con = New OleDbConnection(My.Settings.OneDataConnectionString) 'Create a new instance of the command object 'TODO: Change [ID] to a valid column and [MyTable] to a valid table Using cmd As OleDbCommand = New OleDbCommand("SELECT Count([ID]) FROM [IDStaff] WHERE [StaffName]=@staff AND [PCNAME]=@pc", con) 'Parameterize the query With cmd.Parameters .AddWithValue("@staff", username) .AddWithValue("@pc", pcName) End With 'Open the connection con.Open() 'Use ExecuteScalar to return a single value count = Convert.ToInt32(cmd.ExecuteScalar()) 'Close the connection con.Close() End Using Catch ex As Exception 'Display the error Console.WriteLine(ex.Message) Finally 'Check if the connection object was initialized If con IsNot Nothing Then If con.State = ConnectionState.Open Then 'Close the connection if it was left open(exception thrown) con.Close() End If 'Dispose of the connection object con.Dispose() End If End Try 'Return the row count Return count End Function




Reply With Quote