以文本方式查看主题 - Foxtable(狐表) (http://foxtable.com/bbs/index.asp) -- 专家坐堂 (http://foxtable.com/bbs/list.asp?boardid=2) ---- [求助]关于ListBox控件的一个用法 (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=21391) |
-- 作者:raystar27 -- 发布时间:2012/7/11 7:52:00 -- [求助]关于ListBox控件的一个用法 如果说我想把一个字段从数据库里提取出来的做法应该是 Dim cmd As New SQLCommand Dim dt As DataTable Dim lst As WinForm.ListBox = e.Form.Controls("ListBox") cmd.C cmd.CommandText = "SELECT dbjh1 From kfpt_daa051 " dt = cmd.ExecuteReader() lst.Combolist = dt.GetComboListString("dbjh1") 这样的话所有的dbjh1就提取出来并展示到ListBox里面了。但是如果我想提取一行的多个列的话该怎么办?比如 Dim cmd As New SQLCommand Dim dt As DataTable Dim lst As WinForm.ListBox = e.Form.Controls("ListBox") cmd.C cmd.CommandText = "SELECT dbjh1,dbjh2,dbjh3,dbjh4,dbjh5,dbjh6,dbjh7 From kfpt_daa051 where jh = \'12M190-160\' " dt = cmd.ExecuteReader() lst.Combolist = dt.GetComboListString这句话应该怎么想,如果用到遍历的话应该怎么写?或者有其他的简单办法么?谢谢啦~~ |
-- 作者:don -- 发布时间:2012/7/11 8:06:00 -- Dim sql ,s1,s2 As String Dim Lms As String() ={"dbjh1","dbjh2","dbjh3","dbjh4","dbjh5","dbjh6","dbjh7"} s1=" as A From {kfpt_daa051} where jh = \'12M190-160\' " For Each s2 In Lms sql+ = " Union select " & s2 & s1 Next Dim cmd As New SQLCommand Dim lst As WinForm.ListBox = e.Form.Controls("ListBox") cmd.C \'數據源 cmd.CommandText = sql.Substring(7) lst.Combolist = cmd.ExecuteReader().GetComboListString("A")
[此贴子已经被作者于2012-7-11 8:19:48编辑过]
|
-- 作者:raystar27 -- 发布时间:2012/7/11 8:50:00 -- 回复:(don)Dim sql ,s1,s2 As StringDim Lms As St... 有点没看懂~~就是把那几个字段存放在一个数组里是吧?然后把每一个字段都放在lst.Combolist里面?试了下~~不知道哪有问题~~ |
-- 作者:don -- 发布时间:2012/7/11 8:57:00 -- 你看看合成的SQL是什麼就知道了 |
-- 作者:狐狸爸爸 -- 发布时间:2012/7/11 8:58:00 -- Dim cmd As New SQLCommand
Dim dt As DataTable
Dim lst As WinForm.ListBox = e.Form.Controls("ListBox")
cmd.Connection Name = "数据源"
cmd.CommandText = "select ([产品] + \',\' + [客户]) As a From {订单}"
dt = cmd.ExecuteReader() lst.Combolist = dt.GetComboListString("a")
[此贴子已经被作者于2012-7-11 8:58:22编辑过]
|
-- 作者:don -- 发布时间:2012/7/11 9:02:00 -- 以下是引用狐狸爸爸在2012-7-11 8:58:00的发言:
cmd.Connection Name = "数据源"
cmd.CommandText = "select ([产品] + \',\' + [客户]) As a From {订单}"
dt = cmd.ExecuteReader() lst.Combolist = dt.GetComboListString("a") 哈哈,這個簡單,想複雜了
[此贴子已经被作者于2012-7-11 8:58:22编辑过]
|
-- 作者:blackzhu -- 发布时间:2012/7/11 9:11:00 -- 牛,SQL语句 弄会了,做什么都简单. |
-- 作者:狐狸爸爸 -- 发布时间:2012/7/11 9:20:00 -- 漏掉一个关键词:
Dim cmd As New SQLCommand
Dim dt As DataTable
Dim lst As WinForm.ListBox = e.Form.Controls(" div ListBox?)<>
cmd.Connection Name = "数据源"
cmd.CommandText = "select Distinct ([产品] + \',\' + [客户]) As a From {订单}"
dt = cmd.ExecuteReader() lst.Combolist = dt.GetComboListString("a")
|
-- 作者:raystar27 -- 发布时间:2012/7/11 9:22:00 -- 回复:(狐狸爸爸)Dim cmd As New SQLCommandDim... cmd.CommandText = "select ([产品] + \',\' + [客户]) As a From {订单}" 狐爸,中间的那个\' ,\'木有看懂~~这样的话产品和客户就都能存放在a里面啦?不需要数组啦?
|
-- 作者:raystar27 -- 发布时间:2012/7/11 9:26:00 -- 回复:(狐狸爸爸)漏掉一个关键词: &... cmd.C cmd.CommandText = "select Distinct (dbjh1,dbjh2) As a From kfpt_daa051 where jh = \'12M190-160\'" dt = cmd.ExecuteReader() lst.Combolist = dt.GetComboListString("a") 这样写有错误~~
|