首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 媒体动画 > CAD教程 >

读取数据库中的数据怎样放到ComboBox,该如何解决

2012-05-20 
读取数据库中的数据怎样放到ComboBoxusing Systemusing System.Collections.Genericusing System.Linqu

读取数据库中的数据怎样放到ComboBox
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace Client.Views
{
  public partial class TDAddEditWindow : ChildWindow
  {
LimsService.LimsServiceSoapClient client = new LimsService.LimsServiceSoapClient();
 public TDAddEditWindow()
 {
  InitializeComponent();
  client.GetFormulaListCompleted += new EventHandler<LimsService.GetFormulaListCompletedEventArgs> (client_GetFormulaListCompleted);  
 }

 void client_GetFormulaListCompleted(object sender, LimsService.GetFormulaListCompletedEventArgs e)
  {
  cbxFormulaList.ItemsSource = e.Result;
  cbxFormulaList.DisplayMemberPath = "FormulaName";
  }
  }
}
上面代码在初始化时没有进行数据库查询,请大大们帮忙

[解决办法]
首先你要设置一个实体,然后将数据库读取到的数据集合转为实体集绑定到ComboBox上
参考http://www.cnblogs.com/chengxingliang/archive/2011/03/03/1969824.html
[解决办法]
1 public TDAddEditWindow()
2 {
3 InitializeComponent();
4 client.GetFormulaListCompleted += new EventHandler<LimsService.GetFormulaListCompletedEventArgs> (client_GetFormulaListCompleted);
6
7 client.GetFormulaListAsync();
}
增加了第7行

热点排行