查询 C# 中表名中的单引号

发布于 2024-11-07 19:06:22 字数 354 浏览 5 评论 0原文

我正在尝试从 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

此岸叶落 2024-11-14 19:06:22

也许:

cmd.CommandText = "SELECT * FROM [E4X'MAIN]";

编辑:

我已经到处寻找这个问题的答案,但一无所获。我唯一能说的是,每个人似乎都一致认为这样的表名是一个主意。但我猜既然您已经花了这么多时间,永久重命名表对您来说不是一个选择。但如果确实如此,我建议你接受它。

Perhaps:

cmd.CommandText = "SELECT * FROM [E4X'MAIN]";

?

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.

玩套路吗 2024-11-14 19:06:22

是SQL Server吗?甲骨文?

尝试过吗

cmd.CommandText = @"SELECT * FROM E4X'MAIN";
cmd.CommandText = @"SELECT * FROM [E4X'MAIN]";

It is SQl SERVER? Oracle?

Tried

cmd.CommandText = @"SELECT * FROM E4X'MAIN";
cmd.CommandText = @"SELECT * FROM [E4X'MAIN]";

?

蓝戈者 2024-11-14 19:06:22

仅供参考,我已经找到了解决我的问题的方法。如果我像 shazam 那样构造我的查询,她就会工作!

cmd.CommandText = "SELECT * FROM \`E4X'MAIN.DBF\`;

感谢您的帮助,希望这个答案能帮助其他陷入可怕的命名约定的人

里诺

FYI I have found a solution to my problem. If I structure my query like so shazam she works!!

cmd.CommandText = "SELECT * FROM \`E4X'MAIN.DBF\`;

Thanks for all your help hopefully this answer will help others stuck with horrible naming conventions

Reno

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文