MS Access SQL LIKE query from C #

I have this query for Ms Access and im using the C # and Ole DB commands. It works on Ms Access, but when I pass the request from C # using OleDB, nothing happened. Anyway, here is 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(); } 
+4
source share
2 answers

Queries executed from within a Microsoft Access application typically use * and ? as wildcards for the LIKE operator. OleDb connections to an Access database from an external application must use % and _ wildcards. (The latter are actually the most commonly used wildcards in other dialects of SQL.)

+7
source

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

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

+1
source

Source: https://habr.com/ru/post/1485175/


All Articles