2014-05-23 59 views
1

條款我想全下拉列表,但>>>如何在聲明從entitydatasource使用在使用entitydatasource

我有一個問題

CommandText="SELECT d.[firstName] FROM DentistEntities.Doctors AS d WHERE d.[id] IN (SELECT s.[doctorID] FROM DentistEntities.DoctorsOfSections AS s WHERE s.[sectionID] = 2)" 

這是我的ASP代碼

<asp:DropDownList ID="doctorlist" runat="server" Width="172px" DataSourceID="EntityDataSource2" DataTextField="firstName" DataValueField="firstName"> 
</asp:DropDownList> 
<asp:EntityDataSource ID="EntityDataSource2" runat="server" ConnectionString="name=DentistEntities" DefaultContainerName="DentistEntities" CommandText="SELECT d.[firstName] FROM DentistEntities.Doctors AS d WHERE d.[id] IN (SELECT s.[doctorID] FROM DentistEntities.DoctorsOfSections AS s WHERE s.[sectionID] = 2)"> 
</asp:EntityDataSource> 

但是當我編譯我有這個錯誤

元素類型'Edm.Int32'和CollectionType'Transient.collection [Transient.rowtype(doctorID,Edm.Int32(Nullable = True,DefaultValue =))]'不兼容。 IN表達式僅支持實體,標量和引用類型。不遠的地方謂語,1號線,列69

PLZ任何幫助

謝謝

+0

列'Doctors.id'是否允許'null'並且DoctorsOfSections.doctorID列是否允許'null'?從消息看,它看起來不匹配,您可能需要在SQL語句中使用COALESCE。 –

+0

COALESCE'無法解析爲有效的類型或函數。近簡單的標識符, –

回答

3

有同樣的問題可以試試這個(注意子選擇了「VALUE」關鍵字)任何人:

CommandText="SELECT d.[firstName] FROM DentistEntities.Doctors AS d WHERE d.[id] IN (SELECT VALUE s.[doctorID] FROM DentistEntities.DoctorsOfSections AS s WHERE s.[sectionID] = 2)" 
相關問題