solujic
solujic

Reputation: 1004

OleDbException: Record is deleted. The search key was not found in any record

I'm trying to import DBF file with one table via C# Method. The code works fine for most of the files but one seems to be corrupt. I'm not sure if it's codepage differences that make it corrupt or something else, if anybody has any insight please help!

 public static void LoadDbf(DataTable destinationDataTable, string DbfDbPath, string DbfDbName)
    {
        destinationDataTable.Clear();
        using (var CS = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + DbfDbPath + ";Extended Properties=dBASE III;"))
        {
            try
            {
                string selectTableSyntax = @"SELECT * FROM " + DbfDbName;
                OleDbDataAdapter adapter = new OleDbDataAdapter(selectTableSyntax, CS);
                adapter.Fill(destinationDataTable);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Pogreška prilikom učitavanja baze " + DbfDbName + ".\r\n\r\n" + ex.ToString());
            }
            finally
            {
                CS.Close();
            }
        }
    }

Upvotes: 1

Views: 1097

Answers (1)

solujic
solujic

Reputation: 1004

Fixed it with the help of this article:

http://www.codeproject.com/Articles/24247/Load-a-DBF-into-a-DataTable

Basically it loads the data via BinaryReader and then stores it into DataTable

very elegant code with one class and a method

dataTable = ParseDBF.ReadDBF(fullpath);

Upvotes: 1

Related Questions