Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Incorrect syntax near 'E'
Message
De
12/02/2021 14:23:07
 
 
À
12/02/2021 13:43:57
Information générale
Forum:
C#
Catégorie:
Bases de données
Divers
Thread ID:
01678192
Message ID:
01678194
Vues:
38
>>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
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform