Click here to Skip to main content
15,892,965 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Posted

1 solution

try like this
VB
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
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900