[英]How To Load vb.net Combobox faster
我是 Vb.net 的新手,我使用此代碼從 Mysql 數據庫加載 Combobox。 效果很好,但速度很慢
有沒有辦法在一個查詢中執行所有這些並加載所有組合框或另一種更快地執行此任務的方法?
AbrirDB()
comandomysql.CommandText = "select distinct TblMarcas.marca from TblMarcas order by marca"
Try
Lector = comandomysql.ExecuteReader
Lector.Read()
.cbom.Properties.Items.Clear()
If Lector.HasRows Then
.cbom.Properties.Items.Add(Lector.Item("marca"))
Do While Lector.Read
.cbom.Properties.Items.Add(Lector.Item("marca"))
Loop
Else
End If
Catch ex As Exception
DevExpress.XtraEditors.XtraMessageBox.Show(Err.Number & Err.Description)
If conexion.State = ConnectionState.Open Then conexion.Close()
End Try
CerrarDb()
'CARGO Categorias a treelist
AbrirDB()
comandomysql.CommandText = "select distinct TblCategorias.categoria from TblCategorias order by categoria ASC"
Try
Lector = comandomysql.ExecuteReader
Lector.Read()
.cboc.Properties.Items.Clear()
If Lector.HasRows Then
.cboc.Properties.Items.Add(Lector.Item("categoria"))
Do While Lector.Read
.cbocategoria.Properties.Items.Add(Lector.Item("categoria"))
Loop
Else
End If
Catch ex As Exception
DevExpress.XtraEditors.XtraMessageBox.Show(Err.Number & Err.Description)
If conexion.State = ConnectionState.Open Then conexion.Close()
End Try
CerrarDb()
'CARGO Subcategorias
AbrirDB()
comandomysql.CommandText = "select distinct TblSubcategorias.subcategoria from TblSubcategorias order by subcategoria ASC"
Try
Lector = comandomysql.ExecuteReader
Lector.Read()
.cbos.Properties.Items.Clear()
If Lector.HasRows Then
.cbos.Properties.Items.Add(Lector.Item("subcategoria"))
Do While Lector.Read
.cbos.Properties.Items.Add(Lector.Item("subcategoria"))
Loop
End If
Catch ex As Exception
DevExpress.XtraEditors.XtraMessageBox.Show(Err.Number & Err.Description)
If conexion.State = ConnectionState.Open Then conexion.Close()
End Try
CerrarDb()
任何幫助,將不勝感激。
嘗試:
myCombo.SuspendLayout()
昏暗的表作為新的DataTable()
table.Load(MyDataReader)
myCombo.DataSource =表
myCombo.DisplayMember = “列1”
myCombo.ResumeLayout()
Dim ds As DataTable = yourtable
Dim arr As Object() = (From dc In ds.AsEnumerable Select dc(0)).ToArray
combo.Items.AddRange(arr)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.