Click here to Skip to main content
12,999,580 members (105,861 online)
Rate this:
 
Please Sign up or sign in to vote.
Hii,everyone
there is aproblem in query expression when search by student id's
and error messing about missing operator (Syntax error(missing operator)in query expression'student.id_civil_st like123456'
as in this code :

string conString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=..\\..\\org.accdb";
           OleDbConnection con = new OleDbConnection(conString);
           DataTable dt = new DataTable();
           OleDbDataAdapter oda = new OleDbDataAdapter("SELECT * FROM student WHERE student.id_civil_st like" + int.Parse(textBox1.Text), con);
           oda.Fill(dt);
           dataGridView1.DataSource = dt;
Posted 19-Sep-12 21:48pm
Updated 19-Sep-12 21:52pm
v2
Comments
Kuthuparakkal 20-Sep-12 3:54am
   
You dont even know SQL & how to use it. Learn SQL queries before you jump in
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

Hi,

Use quotation mark when searching for ID,
Query should be like,
OleDbDataAdapter oda = new OleDbDataAdapter("SELECT * FROM student WHERE student.id_civil_st like '" + int.Parse(textBox1.Text), con) + "'";

Another Sample,
Select * from student where student.id_civil_st like '123456';

Hope this resolve your issue
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

LIKE determines whether or not a given character string matches a specified pattern.
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 3

OleDbDataAdapter oda = new OleDbDataAdapter("SELECT * FROM student WHERE student.id_civil_st like % '"+ int.Parse(textBox1.Text)+"' ", con);
  Permalink  
v3
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 4

student.id_civil_st like123456'

As you watch the error message closely you see you miss a space between your 'like' keyword and the value after that.
However as stated above in other suggestions, like is supposed to determine whether or not a given character string matches a pattern. The variables in this pattern are often noted by '%' as such:

Select * from student where student.id_civil_st like '%123456';


Otherwise if you want to compare a fixed number it's just fine to use the equality operator (=)
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.170624.1 | Last Updated 20 Sep 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100