如何将数据库表值添加到组合框项 [英] how to add database table values to combobox items

查看:306
本文介绍了如何将数据库表值添加到组合框项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用
在运行时添加数据库表值以在组合框下拉视图中列出

vb.net编码

how to add database table values to list out in the combobox dropdown view at runtime by using


vb.net coding

推荐答案

Google! http://www. google.co.uk/search?gcx=w&sourceid=chrome&ie=UTF-8&q=link+combobox+to+database [
Google! http://www.google.co.uk/search?gcx=w&sourceid=chrome&ie=UTF-8&q=link+combobox+to+database[^]

Loads of results.

In future, please try to do at least basic research before wasting your time and ours.


这很简单,只需从数据库中创建DataView,然后将ComboBox绑定到此DataView .
以下方法创建DataView:
It''s very simple just create DataView from your DataBase and after that bind your ComboBox to this DataView.
Following Method Creates DataView :
Public Sub CreateDataView()
   Dim objda As OleDbDataAdapter = New OleDbDataAdapter
   Dim objdataset As DataSet = New DataSet
   objda.SelectCommand = New OleDbCommand
   objda.SelectCommand.Connection = Conn 'Conn is your Connection Object.   
   Conn.Open() 'Open DataBase Connection
   objda.SelectCommand.CommandText = "Select * FROM TableName"
   objda.Fill(objdataset, "TableName")
   dv = New DataView(objdataset.Tables("TableName"))
End Sub


在Form Load Event上调用此方法,然后在下面的代码中编写以下代码以将ComboBox与DataView绑定:


Call this method on Form Load Event and below that write following code to bind your ComboBox with DataView :

Me.ComboBox1.DataBindings.Clear()
Me.ComboBox1.DataBindings.Add("Text", dv, "FieldName")


希望对您有帮助. :)


I hope it will help you. :)


这篇关于如何将数据库表值添加到组合框项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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