Board index » cppbuilder » Table does not exist error
michaelkatsilis
CBuilder Developer |
Table does not exist error2005-12-14 03:27:26 PM cppbuilder108 Hi, I'm getting the following database error and have no idea why, programming has ground to a halt unfortunately: "Project mdiapp.exe raised exception class EDBEngineError with message 'Table does not exist. File or directory does not exist. File: D:\MKInventorySystem\tblInvoiceHistory.DB File: D:\MKInventorySystem\tblInvoiceHistory.DBF File: D:\MKInventorySystem\tblInvoiceHistory.txt File: D:\MKInventorySystem\tblInvoiceHistory'. Process stopped. Use Step or Run to continue." The table does exist as is proven in the call to objTable->Locate(sKeyFieldName, sKeyFieldValue, objSearchOptions) (see method TFormItem::SqlExec below) but the error occurs in the call to objSqlQuery->Prepare(); (see method TFormItem::SqlExec below). Here is a code extract: void TFormItem::SaveForm() { AnsiString sSqlQuery = "INSERT INTO tblInvoiceHistory (IVH_ITEM_ID,\ IVH_PURCH_ITEM_ID,\ IVH_ITEM_NAME,\ IVH_CATEgory,\ IVH_BRAND,\ IVH_CURRENCY_CODE,\ IVH_EXCH_RATE_AUD,\ IVH_POSTAGE_COST,\ IVH_POSTAL_INS,\ IVH_EXTRAS,\ IVH_INITIAL_AMT,\ IVH_TOTAL_AMT,\ IVH_STATUS,\ IVH_PAYMENT_TYPE,\ IVH_PAYMENT_DATE,\ IVH_RECEIVE_DATE,\ IVH_COUNTRY,\ IVH_STORE,\ IVH_SELLER,\ IVH_COMMENT) \ VALUES (:item_id,\ :purch_item_id,\ :item_name,\ :category,\ :brand,\ :currency_code,\ :exch_rate_aud,\ :postage_cost,\ :postal_ins,\ :extras,\ :initial_amt,\ :total_amt,\ :status,\ :payment_type,\ :payment_date,\ :receive_date,\ :country,\ :store,\ :seller,\ :comment)"; TQuery * objSqlQuery = new TQuery(InvoiceHistorySource); objSqlQuery->Close(); objSqlQuery->SQL->Clear(); objSqlQuery->SQL->Add(sSqlQuery); // Add bind fields to the query object. objSqlQuery->Params->Items[0]->AsInteger = StrToInt(Trim(txtItemId->Text)); objSqlQuery->Params->Items[1]->AsInteger = StrToInt(Trim(txtPurchaseItemId->Text)); objSqlQuery->Params->Items[2]->AsString = Trim(txtItemName->Text); objSqlQuery->Params->Items[3]->AsString = Trim(dblcboCategory->Text); objSqlQuery->Params->Items[4]->AsString = Trim(txtBrand->Text); objSqlQuery->Params->Items[5]->AsString = Trim(dblcboCurrency->Text); objSqlQuery->Params->Items[6]->AsFloat = StrToFloat(Trim(txtExchangeRateToAUD->Text)); objSqlQuery->Params->Items[7]->AsCurrency = StrToFloat(Trim(txtPostage->Text)); objSqlQuery->Params->Items[8]->AsCurrency = StrToFloat(Trim(txtPostalInsurance->Text)); objSqlQuery->Params->Items[9]->AsCurrency = StrToFloat(Trim(txtExtras->Text)); objSqlQuery->Params->Items[10]->AsCurrency = StrToFloat(Trim(txtInitialAmount->Text)); objSqlQuery->Params->Items[11]->AsCurrency = StrToFloat(Trim(txtTotalAmount->Text)); objSqlQuery->Params->Items[12]->AsString = Trim(dblcboStatus->Text); objSqlQuery->Params->Items[13]->AsString = Trim(dblcboPaymentType->Text); objSqlQuery->Params->Items[14]->AsDateTime = dtPaymentDate->DateTime; objSqlQuery->Params->Items[15]->AsDateTime = dtRecieveDate->DateTime; objSqlQuery->Params->Items[16]->AsString = Trim(dblcboCountry->Text); objSqlQuery->Params->Items[17]->AsString = Trim(txtStore->Text); objSqlQuery->Params->Items[18]->AsString = Trim(txtSeller->Text); objSqlQuery->Params->Items[19]->AsString = Trim(memComment->Text); // Insert the data SqlExec(tblInvoiceHistory, objSqlQuery, "IVH_ITEM_ID", Trim(txtItemId->Text)); } void TFormItem::SqlExec(TTable * objTable, TQuery * objSqlQuery, const String & sKeyFieldName, const String & sKeyFieldValue) { try { TLocateOptions objSearchOptions; objSearchOptions.Clear(); // Prevent duplicate records if(! objTable->Locate(sKeyFieldName, sKeyFieldValue, objSearchOptions)) { MessageDlg("SQL Query: " + objSqlQuery->Text, mtInformation, TMsgDlgButtons() << mbOK, 0); objSqlQuery->Prepare(); // ERROR OCCURS HERE: TABLE NOT FOUND objSqlQuery->ExecSQL(); delete objSqlQuery; objTable->Refresh(); } else { MessageDlg("SqlExec : " + sKeyFieldName + " '" + sKeyFieldValue + "' already exists.", mtInformation, TMsgDlgButtons() << mbOK, 0); } } catch(...) { if (objSqlQuery != 0) { delete objSqlQuery; } MessageDlg("SqlExec : Could not execute query.", mtError, TMsgDlgButtons() << mbOK, 0); //... } } |