Like problem and question

  • Thread starter Thread starter Lourenço Teodoro
  • Start date Start date
L

Lourenço Teodoro

I am using an access database and executing the following piece of code:

IDbConnection con = new
OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=C:\\test.mdb;Persist Security Info=False");
try{
con.Open();
IDbCommand cmd = con.CreateCommand();
cmd.CommandText = "SELECT * FROM MyTable WHERE Tag Like 'A*'";
IDataReader reader = cmd.ExecuteReader();
if(!reader.Read())
MessageBox.Show("Fail");
else
reader.Close();
}

The fail message box is always shown, what means that no data was found. My
column "Tag" has several registers with the value "AlrDigCmd[1]". If I try
to use Tag = 'AlrDigCmd[1]', it works. I need to use wildcards, does anyone
know what am I doing wrong? Also, is the "Like" predicate available to any
provider or it may not be depending on the implementation?

Another issue that I have is that I would like a case insensitive query.
What would be the best way to do it?

I would really appreciate any help.

Lourenço.
 
Try this

SELECT * FROM MyTable WHERE Tag Like 'A%'

That query will be case insensitive.
 
I tried, but it is still not returning any register.

Lourenço.

Andy Gaskell said:
Try this

SELECT * FROM MyTable WHERE Tag Like 'A%'

That query will be case insensitive.

Lourenço Teodoro said:
I am using an access database and executing the following piece of code:

IDbConnection con = new
OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=C:\\test.mdb;Persist Security Info=False");
try{
con.Open();
IDbCommand cmd = con.CreateCommand();
cmd.CommandText = "SELECT * FROM MyTable WHERE Tag Like 'A*'";
IDataReader reader = cmd.ExecuteReader();
if(!reader.Read())
MessageBox.Show("Fail");
else
reader.Close();
}

The fail message box is always shown, what means that no data was found. My
column "Tag" has several registers with the value "AlrDigCmd[1]". If I try
to use Tag = 'AlrDigCmd[1]', it works. I need to use wildcards, does anyone
know what am I doing wrong? Also, is the "Like" predicate available to any
provider or it may not be depending on the implementation?

Another issue that I have is that I would like a case insensitive query.
What would be the best way to do it?

I would really appreciate any help.

Lourenço.
 
Back
Top