避免vb中的组合框中的复制项目 [英] avoiding replicated items from a combobox in vb
本文介绍了避免vb中的组合框中的复制项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在将值从列调用到组合框时遇到问题。我正在使用带有员工详细信息ID,姓名,地址,联系人的表格的mysql
i我正在使用代码
cnn = 新 MySqlConnection
cnn.ConnectionString =( server = localhost; userid = root; password = root; database = hello)
尝试
cnn.Open()
Dim query As String
query = SELECT * from hello.emp
cmd = 新 MySqlCommand(query,cnn)
rdr9 = cmd.ExecuteReader
while rdr9.Read
Dim adr = rdr9.GetString( address)
ComboBox1.Items.Add(adr)
End while
cnn.Close()
Catch ex As MySqlException
MessageBox.Show(ex.Message)
最后
cnn。 Dispose()
结束 尝试
此代码显示组合框中的地址,但如果有8个相同地址的条目,则显示8个相同名称的项目,如:
calcutta
delhi
delhi
delhi
calcutta
delhi
解决方案
尝试query = 从hello.emp中选择不同的地址
query =从hello.emp中选择DISTINCT地址和ComboBox1.Text&
i在调用项目时使用上面的代码并且它工作了
但是有没有其他方法可以先拨打电话并删除所选项目
您好您可以使用此区别。
query = 从hello中选择不同的地址。 EMP跨度>
i am having a problem while calling value from a column to a combobox. i am using mysql with a table emp having employee detail id,name,address,contact
i am using the code
cnn = New MySqlConnection
cnn.ConnectionString = ("server=localhost;userid=root;password=root;database=hello")
Try
cnn.Open()
Dim query As String
query = "SELECT * from hello.emp"
cmd = New MySqlCommand(query, cnn)
rdr9 = cmd.ExecuteReader
While rdr9.Read
Dim adr = rdr9.GetString("address")
ComboBox1.Items.Add(adr)
End While
cnn.Close()
Catch ex As MySqlException
MessageBox.Show(ex.Message)
Finally
cnn.Dispose()
End Try
this code shows the address in the combobox but if there are 8 entries of same address it shows 8 items of same name like:
calcutta
delhi
delhi
delhi
calcutta
delhi
解决方案
Tryquery = "SELECT distinct address from hello.emp"
query = "SELECT DISTINCT address from hello.emp" & ComboBox1.Text & ""
i used the above code while calling the items and it worked
but is there any other way to call first and remove selected items
Hi You can use the Distinct fro this ..
query = "SELECT distinct address from hello.emp"
这篇关于避免vb中的组合框中的复制项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文