0

I've a little question about the select statement with Access database. I want to perform this in a C#/.NET project:

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

For example:

I have a tagName equal to "TEST" and another with "Test". But, right now I retrieve both uppercase and lowercase TagNames. I want to retrieved only lowercase OR uppercase values..

How should I do that? Is there a solution such as Char.IsUpper in Access ?

Thanks in advance, I hope I was clear.

Ars_n

4

2 回答 2

0

试试这个,它可以帮助你

var dataAdapter = new OdbcDataAdapter("SELECT * FROM COMPONENT WHERE TAGNAME COLLATE Latin1_General_CS_AS= '" + tagName + "'"");
于 2013-06-19T12:15:08.880 回答
0

要从 Access 数据库执行区分大小写的 SELECT,您需要使用此处StrComp()记录的函数。

在您的情况下,您的代码应如下所示:

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);
于 2013-06-19T13:12:05.360 回答