sql - 为什么我收到 TADOQuery 选择语句错误?
问题描述
每次我尝试设置此变量的标题时,它都会给我“未指定的错误”,我已经得出结论......
我试图直接从 TADOQuery 设置标题,并将值分配给一个变量,然后将其加载到标题中,但无论哪种方式,我都会得到一个未指定的错误。
qry1.SQL.Text := 'SELECT Number of Games Owned FROM Users WHERE UserID = "' + sLoggedInUser + '";';
qry1.Open;
iCountGames := qry1['Number of Games Owned'];
lblUserGamesOwned.Caption := 'Games Owned: ' + IntToStr(iCountGames);
数据库设计:
Field Name Data Type Description
UserID Short Text Maximum characters is 6
FirstName Short Text Maximum characters is 25
LastName Short Text Maximum characters is 25
Cell Number Short Text Maximum characters is 10
Number of Games Owned Number Integer
我希望代码将值加载到变量中,然后使用该变量设置 TLabel 的标题,但所发生的只是弹出未指定的错误,并且 TLabel 保持不变。
解决方案
我想你只需要在列名周围加上大括号:
SELECT [Number of Games Owned] FROM Users WHERE UserID = "' + sLoggedInUser + '";';
我还建议您使用参数来传递UserId
而不是修改查询字符串。
推荐阅读
- c++ - Visual Studio 2019 无法识别#include
- regex - 删除行尾字符的正则表达式
- swift - Swift:消失数组内容的神秘案例
- asynchronous - 如何在继续执行之前等待异步 chrome.storage.local.get() 完成
- python - Django:通过主页链接到新 URL 时找不到 404 URL
- reactjs - Hook 中不感兴趣的值会导致重新渲染
- javascript - 如何将标签或文本添加到动态添加的复选框?
- java - 使用 Maven 项目运行 JavaFX 时遇到问题
- python - 我不明白为什么这个函数总是返回 none
- javascript - 生成花哨/替代文本