我创建了一个从计算机收集信息(计算机名称、CPU、内存等)的应用程序,但是我很难显示存储在 SQLite 数据库中的信息,当我执行查询时,我得到“NO SUCH TABLE”当我确定我有一个名为“硬件”的表时的消息我做错了什么?
这是我用来执行查询的代码:
procedure TMain.executeButtonClick(Sender: TObject);
var
results: TDataSet;
query: String;
begin
outputMemo.ClearSelection;
query := 'SELECT * FROM hardware;';
try
SQLConnection1.Execute(query, nil, results);
except
on E: Exception do
outputMemo.Text := 'Exception raised with message: ' + E.Message;
end;
ShowSelectResults(results);
end;
每次应用程序运行时都会以编程方式创建数据库文件和表
procedure CheckForDatabase;
var
sldb: TSQLiteDatabase;
sSQL: string;
begin
slDBPath := ExtractFilePath(paramstr(0)) + 'ComputerName.db';
// ShowMessage(slDBPath);
sldb := TSQLiteDatabase.Create(slDBPath);
try
if sldb.TableExists('hardware') then
begin
sSQL := 'DROP TABLE hardware';
sldb.ExecSQL(sSQL);
end;
sSQL := 'CREATE TABLE hardware (id INTEGER PRIMARY KEY, compname TEXT, username TEXT, model TEXT, manufacturer TEXT, domain TEXT, ip TEXT, serialnumber TEXT)';
sldb.ExecSQL(sSQL);
sldb.ExecSQL('CREATE INDEX sHardware ON hardware(CompName);');
sldb.BeginTransaction;
sSQL := 'INSERT INTO hardware(id, compname, username, model, manufacturer, domain, ip, serialnumber) VALUES (1, "AMD8537", "OMonge", "Gigabyte", "Gigabyte", "Workgroup", "192.168.1.11", "8746652");';
sldb.ExecSQL(sSQL);
sldb.Commit;
finally
sldb.Free;
end;
end;
这是 SQLite 数据库:
您可以为我提供的任何帮助将不胜感激。谢谢你。