Quantcast
Channel: Windows Forms Data Controls and Databinding forum
Viewing all articles
Browse latest Browse all 2535

May i ask how to let combo box can bind with database

$
0
0

I develop a program is related combo box bind database but i fail to bind can someone help me take a look

Below is my code

 Dim cnn5 As New OleDb.OleDbConnection
        cnn5.ConnectionString = "Provider=Microsoft.Jet.Oledb.4.0; Data Source=table1.mdb;"


        If Not cnn5.State = ConnectionState.Open Then
        End If
        cnn5.Open()
        Dim dt As New DataTable
        Dim ds As New DataSet
        ds.Tables.Add(dt)
        Dim da As New OleDbDataAdapter

        da = New OleDbDataAdapter("SELECT * FROM table1 WHERE CATEGORY like '%" & txtCATEGORY1.Text& "%'", cnn5)
        da.Fill(dt)


        dgv1.DataSource = dt.DefaultView

        cnn5.Close()

I have 2 category combo box there are txtcategory  and txtcategory1  

Sub Category()
        cnn.Open()
        Dim dt As New DataTable
        Dim cm As New OleDbCommand
        cm.CommandText = " select * from tbl_Category"
        cm.Connection = cnn
        Dim dr As OleDbDataReader = cm.ExecuteReader
        dt.Load(dr)

        txtCATEGORY.DataSource = (dt)
        txtCATEGORY.DisplayMember = "Category"
        txtCATEGORY.ValueMember = "Category"
        txtCATEGORY.Text = ""

txtCATEGORY1.DataSource = (dt)
        txtCATEGORY1.DisplayMember = "Category"
        txtCATEGORY1.ValueMember = "Category"
        txtCATEGORY1.Text = ""
        dr.Close()
        cnn.Close()

I want to display its data separately. At present, my situation is that if the user adds data in txtCATEGORY.Text and txtCATEGORY1.text, data will appear together. I want to split this phenomenon.

For example, when txtCATEGORY show data, txtCATEGORY1 data will not appear. or txtCATEGORY1 show data, txtCATEGORY data will not appear. thanks a lot

Below is the code i try to develop but it no work

   Dim con As OleDbConnection = New OleDbConnection("Provider=Microsoft.Jet.Oledb.4.0; Data Source=Table1;")
        con.Open()
        Dim strCmd As String = " select * from tbl_Category"
        Dim cmd As OleDbCommand = New OleDbCommand(strCmd, con)
        Dim da As OleDbDataAdapter = New OleDbDataAdapter(strCmd, con)
        Dim ds As DataSet = New DataSet()
        da.Fill(ds)
        txtCATEGORY1.DataSource = ds
        txtCATEGORY1.ValueMember = "Category"
        cmd.ExecuteNonQuery()
        con.Close()

Viewing all articles
Browse latest Browse all 2535

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>