使用存储过程中的数据填充组合框! [英] Filling a combobox with data from a stored procedure!

查看:85
本文介绍了使用存储过程中的数据填充组合框!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

< pre lang =   vb> 

我有一个存储过程,我可以填充组合框!

该程序包含SELECT ID,来自TblData的名称以及下面我将发布我的代码到目前为止!

我想有人帮我继续:S Ehere是我的错误



  Dim  n 作为  KonekcijaBaza 
Dim con 作为 SqlConnection
con = n.GetCon()

Dim cmd As SqlCommand
cmd.CommandText = [AP245_IsplatniListi]。[PolniComboDirekcii ]
cmd.CommandType = CommandType.StoredProcedure


Dim da As SqlDataAdapter
Dim ds 作为 DataSet

da.SelectCommand = cmd
da.Fill(ds)







和我付出的费用我有



  Dim  dbl 作为  DBLevel 
Dim dv 作为 DataView
dv = dbl.PolniCombodirekcija()。表( 0 )。DefaultView

cmbDirekci.DisplayMemberPath = direkcija
cmbDirekci.SelectedValue =
sifra_direkcija

解决方案

最简单的解决方案是设置ItemsSource在组合框上等于你有j的数据表你好。然后将DisplayMemberPath和SelectedValuePath属性定义为您希望的列的名称A)作为显示成员,b)是选定的值。



或者(和我的首选方法),是创建一个对象类型的类,然后根据数据集中的结果填充一组对象。然后使用对象集合来填充组合框。



但是,这通常是因为我正在使用在我的组合框中选中的对象做各种事情。 / BLOCKQUOTE>

<pre lang="vb">

I have a stored procedure that I mus fill in the combobox!
The procedure contains "SELECT ID, name from TblData" and below I will post my codei've done so far!
And I would like someone to help me continue :S Ehere is my error

Dim n As New KonekcijaBaza
       Dim con As New SqlConnection
       con = n.GetCon()

       Dim cmd As New SqlCommand
       cmd.CommandText = "[AP245_IsplatniListi].[PolniComboDirekcii]"
       cmd.CommandType = CommandType.StoredProcedure


       Dim da As New SqlDataAdapter
       Dim ds As New DataSet

       da.SelectCommand = cmd
       da.Fill(ds)




and in teh foram load I have

Dim dbl As New DBLevel
       Dim dv As New DataView
       dv = dbl.PolniCombodirekcija().Tables(0).DefaultView

       cmbDirekci.DisplayMemberPath = "direkcija""
       cmbDirekci.SelectedValue = "sifra_direkcija""

解决方案

The simplest solution is to set the ItemsSource on the combo box equal to the the data table you have just filled. Then define the DisplayMemberPath and SelectedValuePath properties as the names of the columns you wish to A) be the display member and b) be the selected value.

Alternatively (and my preferred approach), is to create a Class of your object type, then populate a collection of of your objects based on the results in the dataset. then use the object collection to populate the combo box.

However, that is generally because I am doing various things with the object that gets selected in my combo boxes.


这篇关于使用存储过程中的数据填充组合框!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆