Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Incorrect syntax near 'E'
Message
From
12/02/2021 13:43:57
 
 
To
12/02/2021 13:26:19
General information
Forum:
C#
Category:
Databases
Miscellaneous
Thread ID:
01678192
Message ID:
01678193
Views:
44
Likes (1)
>I have the following code (a self join because I have employees and dependants in the same table):
>
>
>                    using (SqlCommand cmdGetBastaDependants = new SqlCommand("SELECT D.emp_number " +
>                        "FROM Employees as D " +
>                        "INNER JOIN Employees as E ON D.emp_empfk = E.emp_pk" +
>                        "WHERE E.emp_number = @emp_number AND D.emp_active = 1 ", dbConnection))
>                    using (SqlDataAdapter bastaDependantsAdapter = new SqlDataAdapter(cmdGetBastaDependants))
>                    {
>                        cmdGetBastaDependants.Parameters.AddWithValue("emp_number", tatilEmployeesRow["family_eligibility_ud"]);
>                        bastaDependants.Clear();
>                        bastaDependantsAdapter.Fill(bastaDependants);
>}
>
>
>when the last line runs I get an error:
>
>System.Data.SqlClient.SqlException (0x80131904): Incorrect syntax near 'E'.
>
>The SQL works fine if I run it in SSMS. Any ideas what is wrong with it in my code?

"INNER JOIN Employees as E ON D.emp_empfk = E.emp_pk" +
"WHERE E.emp_number = @emp_number AND D.emp_active = 1 ", dbConnection))

Try putting a space after the pk in the first line.


PS

C# allows this construct:

commandtext = @"select etc, etc. etc"
You can paste the query that works in SSMS right into the C# code without all the +, etc, almost like TEXT in VFP
Anyone who does not go overboard- deserves to.
Malcolm Forbes, Sr.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform