Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I have this query for Ms Access and im using C# and Ole DB commands. It works on Ms Access but when I'm passing the query from C# using OleDB, nothing happened. Anyway here's my code:

SQL query

SELECT * FROM tblIssue WHERE  id LIKE '*2*' AND dateChecque LIKE '**'AND +
issueTo LIKE '**' AND byTheName LIKE '**' AND bankName LIKE '**' AND accountNo LIKE '**' +
AND checqueNo LIKE '**' AND amount LIKE '**' AND being LIKE '**'   AND whoDeleted LIKE '**' +
AND whyDeleted LIKE '**' AND dateCreated LIKE '**';

C# code

try
{
    DataTable newDt = new DataTable();
    OleDbDataAdapter newSda = new OleDbDataAdapter(sqlQuery , conn);
    newSda.Fill(newDt);

    if (newDt.Rows.Count > 0)
    {
        dataGridView1.DataSource = newDt.DefaultView;
        _hasData = true;
    }
    else
    {
        _hasData = false;
    }
}
catch (Exception error)
{
    MessageBox.Show(error.ToString()); conn.Close();
}
share|improve this question
Nothings happening? Do you get an error message? Have you actually executed the query or just stored it in the sqlQuery variable? – Darren Davies Jun 8 at 13:56
Whe n I run the query from Ms Access, its executed, but when I used that query to C#, nothing happens. No error. Ok I will edit my code. – ViFer Jun 8 at 14:01
can you provide more code? – Darren Davies Jun 8 at 14:02
@DownVoter - Why downvote my post?? – ViFer Jun 8 at 14:04

2 Answers

up vote 1 down vote accepted

Queries performed from within the Microsoft Access application itself normally use * and ? as wildcard characters for the LIKE operator. OleDb connections to an Access database from an external application should use the % and _ wildcard characters instead. (The latter are actually the more commonly-used wildcard characters in other SQL dialects.)

share|improve this answer
Thanks! Now its working. Actually Im using % before but I changed it to * after doing some research about access. – ViFer Jun 8 at 14:15
Sorry I cant Vote Up my reputation is just 8. And someone downvote my question. :( – ViFer Jun 8 at 14:19
Wow! How come? Hehe! Vote up finish! :) – ViFer Jun 8 at 16:46
Here's some more wildcard references. office.microsoft.com/en-us/access-help/… – Tom Collins Jun 8 at 17:18
Can you vote up my question also? :D – ViFer Jun 8 at 17:21
show 2 more comments

From http://technet.microsoft.com/en-us/library/cc966377.aspx :

Microsoft Jet uses partial match (or "wildcard") characters with the Like operator that are different from those used in most SQL dialects. The asterisk (*) character matches zero or more characters and is equivalent to the percent (%) character in ANSI SQL. The other Microsoft Jet partial match characters are the question mark (?), which matches any character in a single field, and the number sign (#), which matches any digit in a single field.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.