C# IListSource不包含任何数据源。?
我有这个代码,当运行它我得到这个错误 IListSource不包含任何数据源。 我尝试得更多,但没有任何好处C# IListSource不包含任何数据源。?,c#,asp.net,C#,Asp.net,我有这个代码,当运行它我得到这个错误 IListSource不包含任何数据源。 我尝试得更多,但没有任何好处 public static DataSet SelectAll_EmployeeType() { DataSet ds = new DataSet(); string sqlCommand = ""; SNS_Lib.SQL_DB mySQL = new SNS_Lib.SQL_DB(); sqlCommand = "SELECT * FROM E
public static DataSet SelectAll_EmployeeType()
{
DataSet ds = new DataSet();
string sqlCommand = "";
SNS_Lib.SQL_DB mySQL = new SNS_Lib.SQL_DB();
sqlCommand = "SELECT * FROM EmployeeType";
ds = mySQL.SelectFromQuery(sqlCommand);
return ds;
}
private void FillSource()
{
DataSet ds = Client.SelectAll_EmployeeType();
DDL_UserType.DataSource = ds;
DDL_UserType.DataTextField = "Type";
DDL_UserType.DataValueField = "Type";
DDL_UserType.DataBind();
DDL_UserType.Items.Insert(0, "-- Select One");
}
运行此应用程序时,我遇到了此错误
The IListSource does not contain any data sources.
描述:执行当前web请求期间发生未处理的异常。请查看堆栈跟踪以了解有关错误的更多信息以及错误在代码中的起源
异常详细信息:System.Web.HttpException:IListSource不包含任何数据源
源错误:
Line 224://ds.Tables[0].DefaultView
第225行:DDL_UserType.DataValueField=“Type”
第226行:DDL_UserType.DataBind()
第227行:
第228行://将项目添加到第一个位置。此行出错。第226行:DDL_UserType.DataBind();那么:什么是
ds.Tables.Count
?还有:为什么人们使用DataTable
来处理这些东西?;好的,第二个是修辞性的——你不需要回答这个问题;只是第一个;顺便说一句,=new DataSet()
是不必要的,也是浪费的,因为它在末尾的ds=…
行中被丢弃;您还可以从SelectAll\u EmployeeType()
中删除ds
,只需返回mySQL即可代码>