在webservice里定义了方法
[WebMethod]
public List<m_article> GetsimpleList(string strWhere)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("select [BH],[topicbh],[Title],[Author] ");
strSql.Append(" FROM J_Articles ");
if (strWhere.Trim() != "")
{
strSql.Append(" where " + strWhere);
}
strSql.Append(" order by publishdate desc");
DataTable dt= DbHelperSQL.Query(strSql.ToString()).Tables[0];
List<m_article> articles=new List<m_article>();
foreach(DataRow row in dt.Rows)
{
m_article article=new m_article();
article.Title=row["title"].ToString();
article.Author=row["author"].ToString();
articles.Add(article);
}
return articles;
}
在silverlight里绑定
private void UserControl_Loaded(object sender, RoutedEventArgs e)
{
DataBaseOperateSoapClient client = new DataBaseOperateSoapClient();
client.GetsimpleListCompleted += new EventHandler<GetsimpleListCompletedEventArgs>(client_GetsimpleListCompleted);
client.GetsimpleListAsync("");
}
void client_GetsimpleListCompleted(object sender, GetsimpleListCompletedEventArgs e)
{
if (e.Error == null)
{
dataGrid.ItemsSource = e.Result ;
}
}
在这句 dataGrid.ItemsSource = e.Result ;
出现以下错误:
无法将类型“databaseoperateServiceReference.GetsimpleListResponseGetsimpleListResult”隐式转换为“System.Collections.IEnumerable”。存在一个显式转换(是否缺少强制转换?)