Click here to Skip to main content
15,903,831 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi everyone,

I need a help ! I am writing a programming that select that from two different tables, but it always show this error when ever i run it: Incorrect syntax near '@PayrollNumber'....This is my code:

cmd.CommandText = "SELECT PersonalDetails.FirstName, PersonalDetails.MiddleName, PersonalDetails.LastName, offices.Id, offices.Name   FROM PersonalDetail INNER JOIN offices ON (PersonalDetails.@PayrollNumber = offices.PayrollNumber) WHERE (FirstName =  '" + TextBox6.Text + "') and (MiddleNam<e = '" + TextBox7.Text + "') AND (LastName = '" + TextBox8.Text + "')";
Posted
Updated 11-Mar-13 5:13am
v2
Comments
Richard C Bishop 11-Mar-13 11:15am    
If @PayrollNumber is not a column in the PersonalDetail table, then you cannot treat it as one. Also, you are leaving yourself open for sql injection. You should be using parameterized queries.

1 solution

Your code contains at least two syntactic errors - “@PayrollNumber” and “MiddleNam<e”.
For user inputs use Command parameters[^] instead of string concatenation.
 
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