sql query problem with MS Access and C#

Please support our C# advertiser: Intel Parallel Studio Home
Reply

Join Date: Aug 2006
Posts: 1
Reputation: fathih is an unknown quantity at this point 
Solved Threads: 0
fathih fathih is offline Offline
Newbie Poster

Re: sql query problem with MS Access and C#

 
0
  #11
Aug 11th, 2006
Originally Posted by msaqib
sorry, actually u didnt understand my problem. I jsut wanted to know that
if i run "select * from book where name like '*x*' OR description like '*x*';" from the MS Access then it returns some records containing X somewhere in the text.
But if i run it throught C# code and execute the query it returns no records.

why?
"select * from book where name like '*x*' OR description like '*x*';"
replace your query with the following
"select * from book where name like '%x%' OR description like '%x%';"
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 1
Reputation: kursat is an unknown quantity at this point 
Solved Threads: 0
kursat kursat is offline Offline
Newbie Poster

Re: sql query problem with MS Access and C#

 
0
  #12
Jun 19th, 2007
Hi there,
I have the same problem, is there any solution to that. I tried both * and % but nothing changed. it does not return any record.

Regards
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 1
Reputation: JMu is an unknown quantity at this point 
Solved Threads: 0
JMu JMu is offline Offline
Newbie Poster

Re: sql query problem with MS Access and C#

 
0
  #13
Jun 23rd, 2007
Hello.
I ran into the same problem today. Fortunatelly for me , I found the solution.
My old code:
  1. filter+= "(invoice.serie LIKE '%" + txtInvoiceSerie.Text + "%')";
I tried with both % and *. Nothing worked. I searched google, but didn't found answear. Then I tried:
  1. filtru += "(invoice.serie LIKE '" + '%' + txtInvoiceSerie.Text + '%'+"')";
Adding % sepparately, as a char, does the trick. (depending on the access file version, you may need to use * instead of % - the former works on Access 2003 file format).

I hope this helps.
P.S. Sorry for the bad english, it is not my native language.
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 1
Reputation: abd_alrahman111 is an unknown quantity at this point 
Solved Threads: 0
abd_alrahman111 abd_alrahman111 is offline Offline
Newbie Poster

Re: sql query problem with MS Access and C#

 
0
  #14
Sep 30th, 2007
Thank You All
I Had The same problem then when i replaced * with % every thing became right

Here is Some Code :

SQLStatement = SQLStatement + " and StudentName like '%" + textBox26.Text + "%'";
OleDbCommand command = new OleDbCommand(SQLStatement, gConnection);
gDataAdapter.SelectCommand = command;
gDataTable.Clear();
OleDbCommandBuilder gCommandBuilder = new OleDbCommandBuilder(gDataAdapter);
gDataAdapter.Fill(gDataTable);
dataGridView1.DataSource = gDataTable;


Sorry for the bad english, it is not my native language.
my language is Arabic.
I Like Arabic verymuch.
Last edited by abd_alrahman111; Sep 30th, 2007 at 6:55 am.
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 1
Reputation: edusilva is an unknown quantity at this point 
Solved Threads: 0
edusilva edusilva is offline Offline
Newbie Poster

Re: sql query problem with MS Access and C#

 
0
  #15
Oct 26th, 2007
Hello.

I'm having a similar problem. My LIKE sql statements are not retrieving the correct records. The difference, in my case, is that it is returning records, only incorrect records. Let's say the query should return 3 records. Instead of returning 3 different records, it returns the first record 3 times.

If I use *'s, I get no records, which makes be believe the correct wild card card is %. And it's using % that is causing the error described in the first paragraph.

I have already tried to append % surrounded by single quote, double quotes, in the same line as the rest of the string, and in a separate line. Every time I get the same result.

Does anybody have a clue? Any help will be much appreciated.

Thanks a lot in advance
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 1
Reputation: phildaniweb is an unknown quantity at this point 
Solved Threads: 0
phildaniweb phildaniweb is offline Offline
Newbie Poster

Re: sql query problem with MS Access and C#

 
0
  #16
Feb 7th, 2008
Originally Posted by msaqib View Post
sorry, actually u didnt understand my problem. I jsut wanted to know that
if i run "select * from book where name like '*x*' OR description like '*x*';" from the MS Access then it returns some records containing X somewhere in the text.
But if i run it throught C# code and execute the query it returns no records.

why?
Try '%x%' - Access uses * but pure sql uses % in LIKE statements
Reply With Quote Quick reply to this message  
Join Date: Nov 2009
Posts: 1
Reputation: zeroboo is an unknown quantity at this point 
Solved Threads: 0
zeroboo zeroboo is offline Offline
Newbie Poster
 
0
  #17
21 Days Ago
JMu was right, i tried his way and fixed the problem.
Thank you JMU
Reply With Quote Quick reply to this message  
Reply

Message:



Similar Threads
Other Threads in the C# Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC