| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 738 人关注过本帖
标题:如何利用combobox解决这个问题
只看楼主 加入收藏
tonyfire
Rank: 1
等 级:新手上路
帖 子:26
专家分:0
注 册:2006-3-27
收藏
 问题点数:0 回复次数:5 
如何利用combobox解决这个问题

有2个表
table1:
编号 职位
01 经理
02 工程师
03 工人
table2
编号 姓名
01-01 王
01-02 杨
02-01 李
02-02 周
03-01 陈
03-02 郑
我想用第一个combobox显示职位,根据编号另一个combobox显示具有此职位职位的人名
还如何实现这个功能啊?
在此先谢谢了

[此贴子已经被作者于2006-4-4 19:19:32编辑过]

搜索更多相关主题的帖子: combobox 
2006-04-02 19:16
tonyfire
Rank: 1
等 级:新手上路
帖 子:26
专家分:0
注 册:2006-3-27
收藏
得分:0 

自己先顶一下

2006-04-04 19:50
lrvinghu
Rank: 2
等 级:新手上路
威 望:4
帖 子:171
专家分:0
注 册:2006-4-12
收藏
得分:0 
table2
编号 姓名
01-01 王
01-02 杨
02-01 李
02-02 周
03-01 陈
03-02 郑

这个里的编号怎么是这样的,01-01时怎么回事?

2006-04-12 15:16
lrvinghu
Rank: 2
等 级:新手上路
威 望:4
帖 子:171
专家分:0
注 册:2006-4-12
收藏
得分:0 

Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged

Dim arr1 As New ArrayList
sql = "select hua.name as name from hua where hua.id in (select ip.id from ip where ip.pno='" & ComboBox1.SelectedValue.trim & "')"
Dim conn As New SqlConnection(strConn)
Dim comm1 As New SqlCommand(sql, conn)
If conn.State <> ConnectionState.Open Then conn.Open()
Dim rd1 As SqlDataReader = comm1.ExecuteReader
If rd1.HasRows Then
While rd1.Read
arr1.Add(rd1.Item("name"))
End While
End If
ComboBox2.DataSource = arr1
rd1.Close()
comm1.Dispose()
conn.Close()
conn.Dispose()
End Sub
自己对号这改一下就行了


2006-04-12 15:54
Viviwei
Rank: 6Rank: 6
等 级:贵宾
威 望:20
帖 子:344
专家分:0
注 册:2006-4-11
收藏
得分:0 

呵呵,这是一个典型的数据读取器的问题.可以提供给你一种2个combobox的方法
先选职位,有此职位的人则显示在combobox2中
具体的代码如下
imports system.data.sqlclient
Public Class Form1
Inherits System.Windows.Forms.Form
'windows窗体自动生成代码
dim conn as new sqlconnection("server=.;database=Student;integrated security=sspi")
dim comm as new sqlcommand
dim ds as new dataset
dim da as new sqldataadapter
dim reader1 as sqldatareader

dim i as integer
'load事件中的代码
If conn.State = ConnectionState.Closed Then
conn.Open()
End If
comm.Connection = conn
comm.CommandType = CommandType.Text
comm.CommandText = "select * from 职工信息"
reader1 = comm.ExecuteReader()
If reader1.HasRows Then
If reader1.Read Then
For i = 0 To reader1.FieldCount - 1
ComboBoxsel.Items.Add(reader1.GetName(i))
Next
End If
reader1.Close()
If conn.State = ConnectionState.Open Then
conn.Close()
End If
End If
'combobox1中selectindexchanged的代码
ComboBoxfill.Items.Clear()
ComboBoxfill.Text = ""
If conn.State = ConnectionState.Closed Then
conn.Open()
End If
comm.Connection = conn
comm.CommandType = CommandType.Text
comm.CommandText = "select distinct " & ComboBoxsel.SelectedItem & " from 职工信息 "
reader1 = comm.ExecuteReader()
If reader1.HasRows Then
While reader1.Read
ComboBoxfill.Items.Add(reader1(0)) '这个地方与表的字段有关系,要修改
End While
End If
reader1.Close()
If conn.State = ConnectionState.Open Then
conn.Close()
End If
注意:要是多个表的话,需注意各个表之间的联系


爱上思考,爱上编程,爱上.net!
2006-04-12 21:00
tonyfire
Rank: 1
等 级:新手上路
帖 子:26
专家分:0
注 册:2006-3-27
收藏
得分:0 
谢谢楼上个位大虾,小弟在此谢过了
2006-04-15 08:55
快速回复:如何利用combobox解决这个问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.011702 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved