【发布时间】:2016-08-11 17:09:22
【问题描述】:
我是 Vb.net 的新手,我使用此代码从 Mysql 数据库加载组合框。 效果很好,但速度很慢
有没有办法在一个查询中执行所有这些并加载所有组合框或另一种更快地执行此任务的方法?
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()
任何帮助将不胜感激。
【问题讨论】:
-
填写一个 DataTable 并将 CBO.DataSource 绑定到它 示例:stackoverflow.com/a/36142887/1070452
标签: mysql vb.net data-binding combobox