通过组合框过滤数据库 [英] Database Filtering through Combobox

查看:77
本文介绍了通过组合框过滤数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的Frirnds,

我有一个组合框,我已经将其与ms-access数据库绑定了.
我想根据combobox的值从数据库中筛选出一行.
我已经写了代码,但是行不通.那是-

将dim标识为Integer(我的Primery密钥为数字)
ID = ComboBox1.selectedValue
da =新的OledbDataAdapter(从Table_Name中选择*,其中Id =''"&Id&''")
ds = new数据集
da.Fill(ds)

''一些代码将数据呈现给Window Form

错误消息=无法将对象system.data.datarow转换为整数.

谢谢

Dear Frirnds,

I have combobox which i have already binded with a ms-access database.
I want to filter a row from the database based on the value of combobox.
I have written code but that not works. That is -

dim Id as Integer ( My Primery Key is Numeric)
Id = ComboBox1.selectedValue
da = new OledbDataAdapter("Select * from Table_Name where Id=''"& Id &"''")
ds=new Dataset
da.Fill(ds)

'' Some Code to present the data to the Window Form

Error Msg = Cannot covert the object system.data.datarow to integer.

Thanks

推荐答案

尝试这样
Dim cbo As String = Cboid.Text

           Dim str As String = "SELECT DISTINCT(id) FROM sample where ID='" & cbo & "' order by id"

           Dim ds1 As DataTable
           ds1 = objbs.ExcuteQuary1(str)
           CboGroup.DataSource = ds1

           CboGroup.DisplayMember = "ID"
           CboGroup.ValueMember = "ID"
           CboGroup.SelectedIndex = -1

''Bs File
 Public Function ExcuteQuary1(ByVal str As String) As DataTable
        Try


            Dim da As New SqlDataAdapter()

            ' cmd = new SqlCommand();
            cmd.Connection = conopen()
            cmd.CommandType = CommandType.Text
            cmd.CommandText = str
            da.SelectCommand = cmd

            Dim dt As New DataTable()
            da.Fill(dt)
            Return dt
        Catch ex As Exception
            CloseConnection()

            Return Nothing
        Finally
            CloseConnection()
        End Try
    End Function


这篇关于通过组合框过滤数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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