数据库中的SQL逻辑检查 - VB.net [英] SQL logical check in database - VB.net
问题描述
Hello Guys,
我试图访问MSI数据库,我可以在数据库中插入,删除等。
我的问题是如何检查数据库中的现有条目和如果不存在则插入。
我的代码中出现错误。
installer = CreateObject(WindowsInstaller.Installer)
database = installer.OpenDatabase(Path,1)'数据库将被打开进行编辑。
SQLquery =IF NOT EXISTS(SELECT * FROM database WHERE`Feature` ='Complete')INSERT INTO Feature(`Feature`,`Feature_Parent`,`Title `,`Description`,`Display`,`Level`,`Directory_`,`Attributes`)VALUES('Complete','','Complete','','2','1','INSTALLDIR', '0')
View = database.OpenView(SQLquery)---------> 错误:COMException未处理, OpenView,Sql
请协助我解决了代码中的错误。
Hello Guys,
Am trying to access the MSI database, I can insert, delete etc. in the database.
My issue is how to check for existing entry in the database and Insert if not exists.
I get error in my code below.
installer = CreateObject("WindowsInstaller.Installer")
database = installer.OpenDatabase(Path, 1) 'database will be opened for editing.
SQLquery = "IF NOT EXISTS(SELECT * FROM database WHERE `Feature` = 'Complete') INSERT INTO Feature (`Feature`, `Feature_Parent`, `Title`, `Description`, `Display`, `Level`, `Directory_`, `Attributes`) VALUES ('Complete', '', 'Complete', '', '2', '1', 'INSTALLDIR', '0' )"
View = database.OpenView(SQLquery) ---------> Error: COMException was Unhandled, OpenView,Sql
Please assist me in solving the error in the code.
推荐答案
查看文档 [ ^ ],Windows Installer不支持IF NOT EXISTS(...)
子句。您需要发出单独的SELECT
和INSERT
命令。
Looking at the documentation[^], Windows Installer does not support theIF NOT EXISTS(...)
clause. You'll need to issue separateSELECT
andINSERT
commands.
这篇关于数据库中的SQL逻辑检查 - VB.net的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!