c# DataTable select 不适用于特殊字符 #
我有一个数据表选择,例如:
productData.Select("Name = 'AAA BBB # CCC'");
我知道该条目在那里,只是由于 # 字符而不起作用。我已经尝试使用 [] 转义:
productData.Select("Name = 'AAA BBB [#] CCC'");
但它仍然不起作用。我知道对于单引号,我将它们加倍,这样 ' 就变成了 ''。但是我还需要关心哪些其他角色以及如何让这个案例发挥作用。
I have a datatable select like:
productData.Select("Name = 'AAA BBB # CCC'");
I know the entry is there, it just doesn't work because of the # character. I have tried escaping with [] like:
productData.Select("Name = 'AAA BBB [#] CCC'");
but it still doesn't work. I know for single quotes I double them so ' becomes ''. But what other characters do I need to be concerned with and how to get this case to work.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您绝对必须像这样使用DataTables吗?正是由于这个原因,我一直对 DataTable 中基于文本的查询感到非常紧张。
如果可能的话,我建议您开始使用 LINQ。您已经可以使用 DataTable 来做到这一点,例如
这样您就不必担心转义等。如果您使用强类型数据集,它会变得更加简单,因为您可以直接引用属性使用字符串名称。
Do you absolutely have to use DataTables like this? I've always been incredibly nervous of the text-based querying in DataTable for precisely this reason.
If at all possible, I suggest you start using LINQ. You can do that with
DataTable
already, e.g.That way you don't need to worry about escaping etc. If you use a strongly-typed dataset it becomes even simpler, as you can refer to properties directly instead of using string names.
你尝试过这样的事情吗?
Have you tried something like this?