Click here to Skip to main content
15,894,337 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello everyone,

The following code is giving the following error:Syntax error in query. Incomplete query clause.

C#
string commandstring = "SELECT MAX(ADX) FROM @out_table WHERE Date (between @strt_date AND @end_date)";
            OleDbCommand cmd = new OleDbCommand(commandstring, con);
            cmd.Parameters.AddWithValue("@out_table", out_table);
            cmd.Parameters.AddWithValue("@strt_date", dt_start);
            cmd.Parameters.AddWithValue("@end_date", dt_end);
            string val= (string)cmd.ExecuteScalar();

I cannot find the problem. please help me.
Posted
Updated 29-Mar-12 21:37pm
v3

Take out the final set of brackets:
C#
string commandstring = "SELECT MAX(ADX) FROM @out_table WHERE Date (between @strt_date AND @end_date)";
Becomes:
C#
string commandstring = "SELECT MAX(ADX) FROM @out_table WHERE Date BETWEEN @strt_date AND @end_date";
 
Share this answer
 
Comments
Monjurul Habib 30-Mar-12 4:49am    
5!
Find following the corrected query.

SQL
SELECT MAX(ADX) FROM @out_table WHERE Date between @strt_date AND @end_date


Hope this help!
 
Share this answer
 
Comments
Monjurul Habib 30-Mar-12 4:49am    
5!
Use this:

C#
string commandstring = "SELECT MAX(ADX) FROM @out_table WHERE [Date] between @strt_date  AND @end_date";
            OleDbCommand cmd = new OleDbCommand(commandstring, con);
            cmd.Parameters.AddWithValue("@out_table", out_table);
            cmd.Parameters.AddWithValue("@strt_date", dt_start);
            cmd.Parameters.AddWithValue("@end_date", dt_end);
            string val= (string)cmd.ExecuteScalar();


Date is a reserved name then:
It's better to use [Date]
And do not use parenthesis
 
Share this answer
 
v2
Comments
Member 8722300 31-Mar-12 3:17am    
tried this , but the problem is still there :(
PLease tell me what should be the data type dt_start and dt_end, string or datatime???
Shahin Khorshidnia 31-Mar-12 6:10am    
Ensure that Date type in your database is "DateTime" and the type of dt_start and dt_end is "Date"
If You tried the code (In my Solution) and the types are ok, then the problem is not the code. It'is from another part of your application.

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