I have a problem doing a query with my software…
I have a function which builds my query, and then execute it to fill a gridview. But it keep throwing me an exception : “The multi-part identifier “” could not be bound” with several columns.
When I try the query in SQL Management Studio, it just works fine. I really don’t understand. Here’s the query.
SELECT DISTINCT [NonConformite].[Numero],
CAST ([NonConformite].[Numero] AS varchar (255)) AS Champ1,
CAST ([NonConformiteDonneesComplementaires177_4].[Texte2] AS varchar (255)) AS Champ2,
CAST (NonConformite.dbo.[NonConformiteStatut].[Libelle] AS varchar (255)) AS Champ3,
CAST ([NonConformite].[Description] AS varchar (255)) AS Champ4 FROM [NonConformite].[dbo].[NonConformite]
LEFT JOIN NonConformite.dbo.[NonConformiteDonneesComplementaires] as NonConformiteDonneesComplementaires177_4
ON [NonConformite].[Numero] = [NonConformiteDonneesComplementaires177_4].[Numero]
LEFT JOIN NonConformite.dbo.[NonConformiteStatut]
ON [NonConformite].[CpteurStatut] = NonConformite.dbo.[NonConformiteStatut].[Cpteur]
I work on Windows 7 Pro, with Visual Studio 2008, SQL Server 2008 and in ASP.NET C#.
Thank you for your answers !
I would start by breaking the query into aliases – see if that helps things; and unless you are intentionally doing cross-db work (usually a bad idea), drop the db identifier and just use the current db: