I am facing two problems...
(1) When I try to write to a Database (SQLite) by using Delphi XE6, I always get the Database is locked error message. I am certain that I close the database everytime I access it by using the command FDConnection1.Close;
(2) How do I INSERT INTO a table from incoming parameters? I have the following incoming parameters
procedure TStock_Bookkeeping.Write_To_DB(const Stock_Code, Stock_Name,
Tran_Date, Buy_Sell, Price_Per_Share, Num_Shares, Trans_Fee: string);
and tried to write into the table with the following SQL command:
sSQL := 'INSERT INTO Each_Stock_Owned(Stock_Code, Stock_Name, Tran_Date, Buy_Sell,
Price_Per_Share, Num_Shares, Trans_Fee)
VALUES (Stock_Code, Stock_Name, Tran_Date, Buy_Sell, Price_Per_Share,
Num_Shares, Trans_Fee)';
but it does not seem to work...
The following is the complete procedure I am having trouble with
procedure TStock_Bookkeeping.Write_To_DB(const Stock_Code, Stock_Name,
Tran_Date, Buy_Sell, Price_Per_Share, Num_Shares, Trans_Fee: string);
var
query : TFDQuery;
sSQL: string;
begin
query := TFDQuery.Create(nil);
try
ConnectToSQLite;
query.Connection := FDConnection1;
if Stock_Code.IsEmpty then
ShowMessage('Stock Code Cannot Be Empty')
else
if Stock_Name.IsEmpty then
ShowMessage('Stock Name Cannot Be Empty')
else
if Tran_Date.IsEmpty then
ShowMessage('Transaction Date Cannot Be Empty')
else
begin
// sSQL := 'INSERT INTO Each_Stock_Owned(Stock_Code, Stock_Name, Tran_Date, Buy_Sell, Price_Per_Share, Num_Shares, Trans_Fee) VALUES (Stock_Code, Stock_Name, Tran_Date, Buy_Sell, Price_Per_Share, Num_Shares, Trans_Fee)';
sSQL := 'INSERT INTO Each_Stock_Owned(Stock_Code, Stock_Name, Tran_Date, Buy_Sell, Price_Per_Share, Num_Shares, Trans_Fee) VALUES (1,2,3,4,5,6,7)';
query.sql.Text := sSQL;
query.ExecSQL;
query.Open();
end;
finally
query.Close;
query.DisposeOf;
DisconnectFromSQLite;
end;
end;
Any hints will be very appreciated. Thanks in advance.