查询 C# 中表名中的单引号
我正在尝试从 C# 对 dbase IV 表运行查询。我对 C# 的经验并不丰富,我已经无计可施了,因为我的 select 语句失败了,因为我尝试查询的表包含单引号。
我正在使用 ODBC 连接来连接到表,该部分工作正常。如果我重命名它并删除引号,我会在同一个表上运行查询。
我尝试使用反斜杠、使用 2 个单引号对其进行转义,并对查询进行参数化,结果发现这不适用于表名。
命令文本是这样的,这是问题的根源...
cmd.CommandText = "SELECT * FROM E4X'MAIN";
请帮助我完全陷入困境,花了几天的时间寻找解决方案,结果却一次又一次地受挫...
I am trying to run a query on a dbase IV table from C#. I am not all that experienced with C# and I have come to my wits end because my select statement fails because the table I am trying to query contains a single quote.
I am using an ODBC connection to connect to the table and that part works fine. I run a query on the same table if I rename it and remove the quote.
I have tried escaping it with a backslash, using 2 single quotes, and parameterized the query only to find out this doesnt work with table names.
The command text is as so and this is the root of the problem...
cmd.CommandText = "SELECT * FROM E4X'MAIN";
Please Help I am completely stuck and have spent days looking for solutions only to be thwarted time after time...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
也许:
?
编辑:
我已经到处寻找这个问题的答案,但一无所获。我唯一能说的是,每个人似乎都一致认为这样的表名是一个坏主意。但我猜既然您已经花了这么多时间,永久重命名表对您来说不是一个选择。但如果确实如此,我建议你接受它。
Perhaps:
?
Edit:
I've looked everywhere I know to look for an answer to this problem and I've found nothing. The only thing I can say is that everyone seems to be in unanimous agreement that a table name like that is a bad idea. But I'm guessing that since you've spent this much time on it already, renaming the table permanently can't be an option for you. But if somehow it is, I suggest you take it.
是SQL Server吗?甲骨文?
尝试过吗
?
It is SQl SERVER? Oracle?
Tried
?
仅供参考,我已经找到了解决我的问题的方法。如果我像 shazam 那样构造我的查询,她就会工作!
感谢您的帮助,希望这个答案能帮助其他陷入可怕的命名约定的人
里诺
FYI I have found a solution to my problem. If I structure my query like so shazam she works!!
Thanks for all your help hopefully this answer will help others stuck with horrible naming conventions
Reno