Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Incorrect syntax near 'E'
Message
From
12/02/2021 14:23:07
 
 
To
12/02/2021 13:43:57
General information
Forum:
C#
Category:
Databases
Miscellaneous
Thread ID:
01678192
Message ID:
01678194
Views:
39
>>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

Thanks! I broke my glasses last weekend and have been struggling while waiting on the replacement.
I was really missing the TEXT construct, so appreciate the suggestion.
Frank.

Frank Cazabon
Samaan Systems Ltd.
www.samaansystems.com
Previous
Reply
Map
View

Click here to load this message in the networking platform