Error in trying to convert datetime-like-clause command while trying to pass values to the database.

Posted by Anishabathija under ASP.NET on 11/19/2012 | Points: 10 | Views : 867 | Status : [Member] | Replies : 1
Hi ,

I have a line of code as shown below :

cmd = new SqlCommand("Select EmployeeNo, EmployeeName from tblEmployeeDetails where Convert(varchar(10),JoinDate,101) like '2012%' = '" +joindate+ "' and Id='" + id + "' and Name= '" + name + "'' ", conn);

I get the below error:
Incorrect syntax near '='.

Please help.
Thanks




Responses

Posted by: Vuyiswamb on: 11/19/2012 [Member] [MVP] [Administrator] NotApplicable | Points: 25

Up
0
Down
I can spot wrong things from scanning your code, anything that i did not highlight bold breaks your code


cmd = new SqlCommand("Select EmployeeNo, EmployeeName from tblEmployeeDetails where Convert(varchar(10),JoinDate,101) like '2012%' = '" +joindate+ "' and Id='" + id + "' and Name= '" + name + "'' ", conn);


It looks like it should be like this

cmd = new SqlCommand("Select EmployeeNo, EmployeeName from tblEmployeeDetails where

Convert(varchar(10),JoinDate,101) like '2012%' '" and Id='" + id + "'
and Name= '" + name + "'' ", conn);



Thank you for posting at Dotnetfunda
[Administrator]

Anishabathija, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response