I'm trying to pass a SELECT statement to my Access database and have it return the number of rows that match . I then have an If-Else statement, if the rows = 0 then do this, else do this. The problem is is that the If part is always being skipped, even if I put in a value that I know isn't in the database. I've included my code below and any help is greatly appreciated.


OleDbConnection connection = new OleDbConnection(con);
connection.Open();

string inputquery = "SELECT COUNT(*) FROM vmtracker WHERE [Customer Name] = @name";
OleDbCommand query = new OleDbCommand(inputquery, connection);
query.Parameters.Add("@name", OleDbType.Char).Value = name.Text;
int dbresult = 0;
OleDbDataReader reader = query.ExecuteReader();
while (reader.Read())
{
dbresult++;
}

if (dbresult == 0)
{
BUNCH OF STUFF HERE
}
else
{
MessageBox.Show("Name already exists");
}