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

Click here to load this message in the networking platform