Datagrid选择不同的 [英] Datagrid select distinct

查看:74
本文介绍了Datagrid选择不同的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在尝试创建一个Select Distinct查询,但是我陷入了一个Empy组合框或一个显示所有双打的填充组合框的问题.

我有一个带有1个组合框和1个datagrid的表单(form5).
数据网格加载5个列"ID","firm","Fname","mname","Lname"

该公司的公司"将与其他公司中的人有一些双重业务

ID公司Fname Mname Lname
1 AA John N West
2 AA Jim L East
3 BB哈里·西克·朗
4 CC Barry N Klote


我想从组合框中选择公司并过滤数据网格,以便它仅显示所选公司和此处注册的人员.此外,我希望我用来选择公司的组合框失去双打.

我可以加载datagrid和Combobox,但是选择仅指向我选择的记录(网格中的突出显示),并且不进行过滤.有没有人可以给我提供有关如何解决此问题的线索.

Hi,

I''m trying to create a Select Distinct query, but i''m getting stuck with either an empy combobox either a filled combobox that displays all the doubles.

I have a form (form5) with 1 combobox and 1 datagrid.
The datagrid loads 5 collumns "ID", "firm", "Fname", "mname", "Lname"

The collumn "firm" will have some double firms with people in the other collumns

ID Firm Fname Mname Lname
1 AA John N West
2 AA Jim L East
3 BB Harry Sick Long
4 CC Barry N Klote

etc.
I would like to select the firm from a combobox and filter the datagrid so that it only displays the selected firm and the people that are registred here. Furthermore i want the combobox that i use for selecting the firms to lose the doubles.

I can load the datagrid and load the Combobox, but selecting is only pointing to the record (highlights in the grid) i choose and doesn''t filter. Is there anyone that can give me a clue on how to solve this.

Private Sub Form5_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        'TODO: This line of code loads data into the 'Kjelpasser2012DataSet.Employees' table. You can move, or remove it, as needed.
        Me.EmployeesTableAdapter.Fill(Me.passer2012DataSet.Employees)
        'Select DISTINCT "firm" from "Employees" 
        'End Select

    End Sub


  'TODO: This line of code loads data into the 'passer2012DataSet.Employees' table. You can move, or remove it, as needed.

        Dim ds As New passer2012DataSet
        Dim con As New OleDb.OleDbConnection
        Dim da As New OleDb.OleDbDataAdapter("Select DISTINCT firm from Employees", con)
        Dim dt As New DataTable
'i made these text
        'Me.passer2012DataSet.Employees.Open()
        ' da.Fill(ds)
        'dt = ds.Tables(0)

        'databinding()
        cmbfirma.DataSource = ds
        cmbfirma.DisplayMember = "employeeID" 'DataTextField = "employeeID"
        cmbfirma.ValueMember = "Firma" 'DataValueField = "Firma"
        Me.EmployeesTableAdapter.Fill(Me.Kjelpasser2012DataSet.Employees)
       
        con.Close()


感谢你的回复.我似乎没有让我这样工作.

我使用"Me.EmployeesTableAdapter.Fill"方法,是否有可能不需要使用OLEDB连接,还是仍然需要此连接才能正确连接到数据库(访问)?我对您发送的脚本进行了一些更改,但这并不能解决问题.有技巧吗?

组合框填充以下文本.


Thank you for your reply. I don''t seem to get i to work this way.

I use the "Me.EmployeesTableAdapter.Fill" method so is it possible that i don''t need to use the OLEDB connection or do i still need this to correctly connect to the DB (access)? I changed a bit in the script you had sent but this did not do the trick. Any tips?

The combobox fills with the following text.

System.Data.DataViewManagerListItemTypeDescriptor



该消息怎么办?



what to do about this message?

推荐答案

试试这个

Try this one

Dim ds As New DataSet()
Dim con As New OdbcConnection(ConnStr)
Dim da As New OdbcDataAdapter("Select DISTINCT firm from Employees", con)
con.Open()
da.Fill(ds)
dt = ds.Tables(0)

'databinding
dropdownlist.DataSource = ds
dropdownlist.DataTextField = "ID"
dropdownlist.DataValueField = "Firm"
dropdownlist.DataBind()


con.Close()



最好的问候,
@iamsupergrasya



Best Regards,
@iamsupergrasya


这篇关于Datagrid选择不同的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆