Click here to Skip to main content
15,888,968 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
C#
string query = string.Format( "Select {0}.{1},{2},{3}, {9}.{4},{5},{6} ,{7},{8} From {0} ;



i got this error Syntax error in string in query expression '(Mid(AttendanceLogs.InTime,EmployeeId,0) = Mid(Format(DateAdd(AttendanceDate,-4, NOW()), 'YYY-mm-dd),EmployeeId,0))'.
Posted
Updated 5-Nov-12 20:43pm
v2

The whole idea is wrong in principle. Your data you use for composing the query may come from UI, and anything can come, including… some SQL code fragments. This simple idea is the base of the well-known exploit called "SQL Injection". You cannot afford this to happen.

Please see: http://en.wikipedia.org/wiki/SQL_injection[^].

Please see this article and pay attention for the section "Parametrized statement". Even all aspects of the exploit and its mitigation can be very complex (I recently saw a whole thick book on this single topic), parametrized statements is a principle way fighting the problem.

This is how it looks in ADO.NET:
http://msdn.microsoft.com/en-us/library/yy6y35y8.aspx[^],
http://msdn.microsoft.com/en-us/library/ms254953.aspx[^].

Good luck, stay safe,
—SA
 
Share this answer
 
v2
Comments
Mohamed Mitwalli 6-Nov-12 1:50am    
5+
Sergey Alexandrovich Kryukov 6-Nov-12 2:07am    
Thank you, Mohamed.
--SA
Hi There,

I think you are trying to use MID as function.
If this is true, there are couple of problems I assume.

1. MID is function to find a substring from a coulmn. The way you have used doesn't seem right. The syntax for MID is
SQL
SELECT MID(column_name,start[,length]) FROM table_name


2. MID I think is not available in SQL 2008. It was/is there in Access. You can use substring method in SQL 2008. The syntax for the substring is same
SQL
SELECT substring(column_name,start[,length]) FROM table_name


In both cases length is an optional parameter.

Hope that helps
Milind
 
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