从整个Collumn获取值到ComboBox [英] Getting values from an entire Collumn to a ComboBox
问题描述
我试图用我的数据库中的整个Collumn填充一个ComboBox,但我不想让它与DataSet或类似的东西。我希望通过代码
有人可以帮助
不知道该怎么办
< pre lang =vb> Dim combo As ComboBox
combo = frmRD.cboNomCoop
frmRD.cboNomCoop.Items.Add( )
TesterJSR写道:我试图填充整个ComboBox来自我的数据库的collumn 但我不想让它与DataSet 或类似的东西。我希望它通过代码
这不是那样的工作!为什么?请参阅Ryan评论。
richcb写道:
DataSet用于编码。它只是从数据源检索的数据的集合(或根据MSDN的内存缓存)。 DataTable是检索数据的表。你怎么去获取数据呢?
我去
创建数据表
每个行 Datarow Gridview1.Datarow
Dim cValue as String = ctype(rows, LabelorTextbox,textbox).text \\你在这里获取单元格值
\\\插入值 此处创建的数据表
下一步
combobox.datasource =您创建的数据表
combobox.displaymember =您的数据表列名称或 id
combobox.valuemember =您的数据表值列名或 id
combobox.databind
此代码尚未经过测试但在我自己的应用程序中测试的逻辑数百万次;)我希望它可以帮助你。
Hi, im trying to fill a ComboBox with an entire Collumn from my database but I don''t want it to do with a DataSet or something like that. I want it via Code
Can someone plz help
Don''t know what to do
Dim combo As ComboBox
combo = frmRD.cboNomCoop
frmRD.cboNomCoop.Items.Add("")
TesterJSR wrote:im trying to fill a ComboBox with an entire Collumn from my database but I don''t want it to do with a DataSet or something like that. I want it via Code
It''s not work like that! Why? See Ryan comment.
richcb wrote:
DataSet is used in coding. It is just a collection(or an in-memory cache according to MSDN) of data retrieved from a datasource. DataTable is a table of retrieved data. How else are you going to get data?
I d go with
Create A DataTable
for each rows as Datarow in Gridview1.Datarow Dim cValue as String=ctype(rows,"LabelorTextbox",textbox).text \\you are getting the cell value here \\insert the value to your created Datatable here Next combobox.datasource=your created datatable combobox.displaymember=your datatable column name or id combobox.valuemember=your datatable value column name or id combobox.databind
This code has not been tested but the logic tested in my own applications million times ;) i hope it helps you.
这篇关于从整个Collumn获取值到ComboBox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!