0

I am using the below code to get the record from a access database. Now i got the below error Syntax error (missing operator) in query expression. I can't able to understand this issue. Please help me to fix this issue.

cmd = new OleDbCommand(@"Select * from tbl_men_schedule where fld_mem_id=" + 0 + " and  fld_startdate=" + Convert.ToDateTime(txt_startDate.Text) + " and fld_enddate=" + Convert.ToDateTime(txt_enddate.Text) + "", con);
 da = new OleDbDataAdapter(cmd);
 DataSet ds = new DataSet();
 da.Fill(ds);

Syntax error (missing operator) in query expression 'fld_mem_id=0 and  fld_startdate=1/4/2013 12:00:00 AM and fld_enddate=4/11/2013 12:00:00 AM'.
3
  • the error itself is self explanatory and suggest how you can fix. Commented Mar 16, 2013 at 3:47
  • looks like you forgot the quotes... Commented Mar 16, 2013 at 4:04
  • user2063626 I would like to fix my issue. Commented Mar 16, 2013 at 4:05

3 Answers 3

1

If fld_startdate and fld_enddate are Date/Time data type, enclose those date values with the # delimiter.

where
        fld_mem_id=0
    and fld_startdate=#1/4/2013 12:00:00 AM#
    and fld_enddate=#4/11/2013 12:00:00 AM#

If they are text data type, enclose them with quotes.

where
        fld_mem_id=0
    and fld_startdate='1/4/2013 12:00:00 AM'
    and fld_enddate='4/11/2013 12:00:00 AM'

However if you use a parameter query instead, you wouldn't need to delimit those values.

Sign up to request clarification or add additional context in comments.

Comments

0

Your statement should be -

"Select * from tbl_men_schedule where fld_mem_id=" + 0 + " and  fld_startdate='" + Convert.ToDateTime(txt_startDate.Text) + "' and fld_enddate='" + Convert.ToDateTime(txt_enddate.Text) + "'"

Hope this helps you

Comments

0

If you hardcoding "0"... and you're missing single quotes.

"Select * from tbl_men_schedule where fld_mem_id=0 and fld_startdate='" + 
txt_startDate.Text + "' and fld_enddate='" + 
txt_enddate.Text + "'"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.