i have created one database in which there is one table Supplier, its primary key is SCode. i have one more table Quotation, in which i have created SCode as Foreign Key.nw i want to allow user to select SCode from Combobox in Quotation table. Format. hw 2 add databinding to a combo. when i create it as

Combobox1.databindings.clear()
Combobox1.DataBindings.Add("text",dv,"SupCode")

where dv is obj of DataView. t displays only one SCode which is th first record in SCode.
i.e there is only one item in Combo.
when i put above code in Loop, as

Dim ds As DataSet
        Dim s As String = "SELECT SupCode From supplier"
        Dim a As New OleDbDataAdapter(s, connquot)
        ds = New DataSet
        a.Fill(ds, "Supplier")
        Dim v As New DataView(ds.Tables("Supplier"))
        Dim c As CurrencyManager
        c = CType(Me.BindingContext(v), CurrencyManager)
        Dim i As Integer
        c.Position = 0
        combobox1.DataBindings.Clear()
        For i = 0 To c.Count

            ComboBox1.DataBindings.Add("text", v, "SupCode")
            c.Position += 1
        Next

it displays error of two data bindings in item of combo.
hw 2 move from one ComboBox.Item(0) to ComboBox.Item(1) to another and hw 2 add data as DataBindings .

plz help.
thnks in advance

see this code, this my code to get data into combobox :

Private Sub BacaData()
        Dim i, k As Integer
        Dim cmdStudent As New SqlCommand
        Dim daStudent As New SqlDataAdapter
        Dim dsStudent As New DataSet
        Dim dtStudent As New DataTable
        Dim conn As SqlConnection

        conn = GetConnect()
        Try

            cmdStudent = conn.CreateCommand
            cmdStudent.CommandText = "SELECT * FROM Student"
            daStudent.SelectCommand = cmdStudent
            daStudent.Fill(dsStudent, "Student")
            dtStudent = dsStudent.Tables("Student")
            For i = 0 To dtStudent.Rows.Count - 1
                cmbNis.Items.Add(dtStudent.Rows(i).Item(0))
            Next

        Catch ex As Exception
            MsgBox("Error: " & ex.Source & ": " & ex.Message, MsgBoxStyle.OKOnly, "Connection Error !!")
        End Try
        conn.Close()
    End Sub
commented: nice snippet +1
commented: thanks +1

i hav also got another method

Dim ds As DataSet
        Dim s As String = "SELECT SupCode From Supplier"
        Dim a As New OleDbDataAdapter(s, connquot)
        ds = New DataSet
        a.Fill(ds, "Supplier")
        Dim v As New DataView(ds.Tables("Supplier"))
        Dim c As CurrencyManager
        c = CType(Me.BindingContext(v), CurrencyManager)
        ComboBox1.DataBindings.Clear()
        ComboBox1.DataSource = ds
        ComboBox1.DisplayMember = "Supplier.SupCOde"
        ComboBox1.ValueMember = "Supplier.Supcode"

it cn b implimented in this way also

thank u. bt i havnt started with SQL Server. i wil try ur method.
i hav solved that . it can be implmented in that way also

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.