我试图在DropDownList菜单中显示2列。要做到这一点,
当我在SSMS中执行以下sql查询时,
"SELECT (convert(varchar,Cost_ID) +' , '+ Item_Description) FROM Cost_ID"
它带来了所需的输出。但是当我在Microsoft Visual Studio 2012数据源中添加它时,即
<asp:SqlDataSource ID="SqlDataSource12" runat="server" ConnectionString="Data Source=MEHDI-PC\SQLEXPRESS;Initial Catalog=PIMS;Integrated Security=True" ProviderName="System.Data.SqlClient" SelectCommand="SELECT (convert(varchar,CostID) +' , '+ Item_Description) FROM Cost_ID"></asp:SqlDataSource>
运行程序时出现以下错误:
DataBinding: 'System.Data.DataRowView' does not contain a property with the name 'Cost_ID'.
知道我哪里错了吗?
谢谢。
答案 0 :(得分:2)
您的SQL语句未提供CONVERT
操作的列名:
SelectCommand="SELECT (convert(varchar,CostID) +' , '+ Item_Description) FROM Cost_ID"
将其更改为:
SelectCommand="SELECT (convert(varchar,CostID) +' , '+ Item_Description) Cost_ID FROM Cost_ID"