OLEDB Exception: The search key was not found in any record

  • Thread starter Thread starter temp
  • Start date Start date
T

temp

Greetings!

I've written a console application to perform some trivial database
routines. When I run the application, it catches the an OleDbException
that states "The search key was not found in any record." My C# code
follows:

=============== snip ==========================
OleDbCommand cmd = new OleDbCommand(sqlstmt, new
OleDbConnection(cnct));

try
{
cmd.Connection.Open();
cmd.ExecuteNonQuery();
cmd.Connection.Close();
}
catch(Exception e)
{
Console.WriteLine(e.Message);
Console.Read(); // used to pause application long enough to read
message
}

cmd.Dispose();
=============== snip ==========================

sqlstmt = "DELETE FROM Accounts WHERE AccountID > 3"
cnct = "PROVIDER=MICROSOFT.JET.OLEDB.4.0;DATA
SOURCE=data_source;Persist Security Info=False;Jet OLEDB:Database
Password=password"
where data_source is the fully qualified local path of the database and
password is, well, obvious (I hope).

I've checked the database and it contains the Accounts table and
AccountID column. The AccountID column does have numbers greater than
three.

I have run this application before in the past with success. It is an
enigma to me why it is no longer functioning. I did recently install
the .NET Framework 2.0 update, but even after uninstalling it, I still
received the exception.

Any assistance that could be provided would be greatly appreciated.

Thanks.

Tim
 
This error often means that the database has become corrupted.
To coerrect the error the database needs to be repaired. If the database is
on a remote server download the database and foillow the instructions below
to repair the database. Open the database in Microsoft Access, click on the
'Tools' menu and select 'Database Utilities -> Compact and Repair Database'.
or
http://support.microsoft.com/?id=301474
 
Back
Top