如何使用 C# 在 MS-Access 中的查询中使用带有通配符的 LIKE 运算符
我在 C# 应用程序中使用 MS Access 数据库,需要传递类似参数化的查询。我发现各种文件说我们可以使用“*”或“?”作为通配符。但是当我尝试将其添加到我的查询中时,它会抛出异常。
实际上 MSAccess 使用类似这种格式... LIKE "United" {这里双引号是强制性的。}但是作为我的 C# 代码中的字符串,我无法在运行时创建 " 。如果我在我的 C# 代码中使用 "字符串不止一次出现红色波浪。
所以我需要一种使用具有通配符支持的查询的方法。
我的字符串是这样的
SELECT student.roll_no, student.s_name, fee.fee_date, (fee.adm_fee+fee.mon_fee+fee.lib_fee+fee.exm_fee) AS fee, class.c_name
FROM class
INNER JOIN (fee INNER JOIN student ON fee.s_id = student.s_id) ON (fee.c_id = class.c_id) AND (class.c_id = student.c_id)
WHERE student.s_name Like ""\""*" + name + "\"*";
,我希望命令文本中的类似条件为 ... WHERE Student.s_name Like "*xyx*"
I am using MS Access database in my C# app, where I need to pass parameterized-like query. I came around various documents saying we can use "*" or "?" as wildcards. But when i try to add it to my query it throws exception.
Actually MSAccess uses like in this format ... LIKE "United" {here double quotes are mandatory.} But as a string in my C# code i cant create " in runtime. If i use " in my string more than once a red wave appears.
So I need a way to use query with wildcard support.
My string is this
SELECT student.roll_no, student.s_name, fee.fee_date, (fee.adm_fee+fee.mon_fee+fee.lib_fee+fee.exm_fee) AS fee, class.c_name
FROM class
INNER JOIN (fee INNER JOIN student ON fee.s_id = student.s_id) ON (fee.c_id = class.c_id) AND (class.c_id = student.c_id)
WHERE student.s_name Like ""\""*" + name + "\"*";
I want my like condition in my command text as ... WHERE student.s_name Like "*xyx*"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为您的字符串格式可能不正确(当然,这是假设您收到 SQL 异常,因为您没有提及有关异常的任何详细信息:))
I think you may just have the formatting in your string incorrect (of course, that's assuming you're getting an SQL Exception, since you didn't mention any details about the Exception :))