Click here to Skip to main content
15,885,036 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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 :

C#
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
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

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,
SQL
Select * from student where student.id_civil_st like '123456';

Hope this resolve your issue
 
Share this answer
 
LIKE determines whether or not a given character string matches a specified pattern.
 
Share this answer
 
C#
OleDbDataAdapter oda = new OleDbDataAdapter("SELECT * FROM student WHERE student.id_civil_st like % '"+ int.Parse(textBox1.Text)+"' ", con);
 
Share this answer
 
v3
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 (=)
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900