福利局在这里,所以请去容易....WPF - 从DAL将数据传递到UI
我在旅途中的WPF项目,我创建了一个数据访问层,我得到我所需要的数据与下面的代码:
public static List<Model.CountryList> GetAllCountriesList()
{
SqlConnection connection = new DatabaseConnection().ConnectToBooze();
SqlCommand cmd = new SqlCommand();
SqlDataReader reader;
SqlDataAdapter da = new SqlDataAdapter();
cmd.CommandText = "dbo.spGetAllCountries";
cmd.CommandType = CommandType.StoredProcedure;
cmd.Connection = connection;
connection.Open();
reader = cmd.ExecuteReader();
var CompanyList = new List<Model.CountryList>();
while (reader.Read())
{
while (reader.Read())
{
var Cli = new Model.CountryList();
Cli.CountryID = Convert.ToInt32(reader["CountryID"]);
Cli.CountryName = reader["CountryName"].ToString();
//Add the country to Country List
CompanyList.Add(Cli);
}
}
//Return list
return CompanyList;
}
我在挣扎的是,我如何将这从DAL传递到我的表示层?我曾经想过的是在表现层上创建一个'Data'类,它从我的DAL调用上面的方法并返回这个列表,但是,我不确定如何做到这一点,而不会'不能隐式地将类型列表转换为列表'错误,我曾试过的是:
public static List<Model.CountryList> GetAllCountries()
{
return DataAccessLayer.DatabaseGets.GetAllCountriesList();
}
感谢您的指导。
似乎没给我。你可以更具体一些你看到的错误。也许发布整个错误? – Versatile
好吧,我是个白痴。我在表示层使用了不同的模型,因此出现了错误。现在通过在DAL中完全引用模型来解决它。谢谢你的帮助。 – Leonidas199x
在发布答案后马上看到你的评论,很高兴你明白了! – JSteward