0

I want to retrieve data frm my DB in a datacombo what event nd property shud i use plz help me with the single line code to retrieve data

2
Contributors
3
Replies
4
Views
8 Years
Discussion Span
Last Post by Jx_Man
0
Private Sub ReadData()
        Dim i As Integer

        con.ConnectionString = ("Provider = Microsoft.JET.OLEDB.4.0;Data Source= D:\Only Me\Authors.mdb")
        Try

            cmdOle = con.CreateCommand
            cmdOle.CommandText = "SELECT * FROM Authors "
            da.SelectCommand = cmdOle
            da.Fill(dsOle, "Authors")
            dtOle = dsOle.Tables("Authors")
            For i = 0 To dtOle.Rows.Count - 1
                cmbAuthor.Items.Add(dtOle.Rows(i).Item(1))
            Next

        Catch ex As Exception
            MsgBox("Error: " & ex.Source & ": " & ex.Message, MsgBoxStyle.OKOnly, "Koneksi Error !!")
        End Try
        con.Close()
End Sub

in looping function ReadData will fill cmbAuthor with 2nd column from table author (.item(1), index start from 0). cmbAuthor.Items.Add(dtOle.Rows(i).Item(1))

0

if i want to store data from datacombo of a particular field of the table of a database the cmbAuthor u mentioned and the code cmbAuthor.Items.Add(dtOle.Rows(i).Item(1)) will it be sufficient bcoz no where else u mentioned the field name.....

0

I was told u in previous post, I said the index of item means index of column on your table.but you can change with :
cmbAuthor.Items.Add(dtOle.Rows(i).Item("ColumnName"))

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.