vb.net 组合框手册并从 db 加载数据
Posted
技术标签:
【中文标题】vb.net 组合框手册并从 db 加载数据【英文标题】:vb.net combobox manual and load data from db 【发布时间】:2018-07-20 23:56:32 【问题描述】:Private Sub delivery_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) 处理 MyBase.Load
sel.Items.Add("allitems")
MsgBox("alert")
Me.EntryTableAdapter.Fill(Me.TailerDataSet.entry)
viewdata.Visible = False
ConnectionState = "Data Source=SWTEAM-II-5\SQLEXPRESS;Initial Catalog=tailer;User ID=sa;Password=123"
con = New SqlConnection(ConnectionState)
con.Open()
Dim sqlquery As String
sqlquery = "Select p_name from entry"
cmd = New SqlCommand(sqlquery, con)
Dim rd As SqlDataReader = cmd.ExecuteReader
Dim dt As DataTable = New DataTable
dt.Load(rd)
dt.Rows.Add("allitems")
sel.ValueMember = "p_name"
sel.DisplayMember = "p_name"
sel.DataSource = dt
仅显示 db 值而非手动值的组合框
【问题讨论】:
【参考方案1】: Dim sqlquery As String
sqlquery = "Select p_name from entry"
cmd = New SqlCommand(sqlquery, con)
Dim adapter As New SqlDataAdapter(cmd)
sel.Items.Add("allitems")
Dim dap As New SqlDataAdapter("SELECT * FROM entry", con)
Dim ds As New DataSet
dap.Fill(ds)
For i As Integer = 0 To ds.Tables(0).Rows.Count - 1
sel.Items.Add(ds.Tables(0).Rows(i).Item("p_name"))
Next
【讨论】:
以上是关于vb.net 组合框手册并从 db 加载数据的主要内容,如果未能解决你的问题,请参考以下文章