使用LIKE'*'的C#数据库查询(访问) [英] C# Database Query (Access) using LIKE '*'

查看:65
本文介绍了使用LIKE'*'的C#数据库查询(访问)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我正在使用来自
的数据库类 http://www.codeproject.com/KB/database/csharpaccessdb.aspx
而且在大多数情况下,它完全可以按照我的要求工作,这很棒.

当我的一个查询使用LIKE``*''条件时遇到一个问题.出于某种原因,每当使用*时,它都不起作用.

让我举个例子...
从书中选择书名,书名如明天,战争爆发";
Access和C#中的工作

从书籍中选择标题,如明天*"之类的标题;
可在Access中工作,但不能在C#中工作

我似乎无法找出*为何不起作用.我到了要从可以正常工作的Access查询直接复制查询的阶段,在该查询中它返回正确的结果,但是当我将其放入C#时,它根本不起作用.其他所有不涉及LIKE``*''的查询都可以在C#中与Access完全相同的结果运行,因此连接到数据库没有问题.

如果有任何建议,那将是很大的帮助!

谢谢,
Josh.

Hi Everyone,

I''m using the database class from
http://www.codeproject.com/KB/database/csharpaccessdb.aspx
and for the most part it has worked exactly how I want, which is great.

I came across a problem when one of my queries uses the LIKE ''*'' condition. For some reason, whenever * is used, it doesn''t work.

Let me give an example...
SELECT Title FROM Books WHERE Title LIKE ''Tomorrow, When The War Began'';
WORKS in Access and C#

SELECT Title FROM Books WHERE Title LIKE ''Tomorrow*'';
Works in Access, but not in C#

I can''t seem to find out why the * doesn''t work. I got to the stage where I was copying the query directly from a working Access query where it returns the correct results, but when I put it in C#, it just doesn''t work. Every other query that doesn''t involve LIKE ''*'' works in C# with the exact same results as Access, so there isn''t a problem connecting to the database.

If there are any suggestions, that would be a great help!

Thanks,
Josh.

推荐答案

我不知道构建查询的代码是什么样的,但是作为猜测,请尝试在包含"Tomorrow *"的字符串之前使用@
I dont what the code that builds the query looks like, but as a guess, just try using an @ before the string that contains ''Tomorrow*''.


嗨Abhinav,

感谢你的及时回复.我在网上四处寻找C#中的更多Access和SQL,发现如果在C#中使用%而不是*,它将可以正常工作.在Access中,您只能将*用作通配符(我承认,通常使用SQL Server,我最初使用%作为通配符来发现它不起作用.)

有点烦人(因为我通常在Access中编写查询,然后将其复制,然后复制,需要记住现在更改所有通配符),但至少现在可以正常工作了.

再次感谢您的及时答复.

乔希.
Hi Abhinav,

Thanks for your prompt reply. I looked around online for some more Access and SQL in C#, and found that if I used a % instead of a * in C# it will work. In Access, you can only use * as a wildcard (I will admit, normally using SQL Server I initially used % as a wildcard to find that it didn''t work.)

A little bit annoying (as I normally write the queries in Access and then copy then over, need to remember to change all the wildcards now), but at least it''s working now!

Again, thanks for your prompt reply.

Josh.


这篇关于使用LIKE'*'的C#数据库查询(访问)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆