简体   繁体   English

C#和MS Access 2010区分大小写的SELECT

[英]C# and MS Access 2010 case-sensitive SELECT

I've a little question about the select statement with Access database. 我对Access数据库的select语句有一个小问题。 I want to perform this in a C#/.NET project: 我想在C#/。NET项目中执行此操作:

var dataAdapter = new OdbcDataAdapter("SELECT * FROM COMPONENT WHERE TAGNAME = '" + tagName + "'");

For example: 例如:

I have a tagName equal to "TEST" and another with "Test". 我有一个tagName等于“ TEST”,另一个带有“ Test”。 But, right now I retrieve both uppercase and lowercase TagNames. 但是,现在我同时检索了大写和小写的TagName。 I want to retrieved only lowercase OR uppercase values.. 我只想检索小写大写值。

How should I do that? 我应该怎么做? Is there a solution such as Char.IsUpper in Access ? 在Access中是否有诸如Char.IsUpper之类的解决方案?

Thanks in advance, I hope I was clear. 在此先感谢,希望我表示清楚。

Ars_n Ars_n

试试这个,它可能对您有帮助

var dataAdapter = new OdbcDataAdapter("SELECT * FROM COMPONENT WHERE TAGNAME COLLATE Latin1_General_CS_AS= '" + tagName + "'"");

To do a case-sensitive SELECT from an Access database you need to use the StrComp() function, documented here . 要从Access数据库进行区分大小写的SELECT,您需要使用StrComp()函数( 在此处进行记录)

In your case, your code should look something like this: 在您的情况下,您的代码应如下所示:

int vbBinaryCompare = 0;
var cmd = new OdbcCommand();
cmd.Connection = con;  // con is an open OdbcConnection
cmd.CommandType = System.Data.CommandType.Text;
cmd.CommandText = 
        "SELECT * FROM COMPONENT " +
        "WHERE StrComp([TAGNAME], ?, ?) = 0";
cmd.Parameters.AddWithValue("?", tagName);
cmd.Parameters.AddWithValue("?", vbBinaryCompare);
var dataAdapter = new OdbcDataAdapter(cmd);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM