954,515 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

How to retriev data frm DB in datacombo

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

asmit1987
Newbie Poster
22 posts since Sep 2008
Reputation Points: 10
Solved Threads: 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))

Jx_Man
Nearly a Senior Poster
3,329 posts since Nov 2007
Reputation Points: 1,372
Solved Threads: 444
 

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.....

asmit1987
Newbie Poster
22 posts since Sep 2008
Reputation Points: 10
Solved Threads: 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"))

Jx_Man
Nearly a Senior Poster
3,329 posts since Nov 2007
Reputation Points: 1,372
Solved Threads: 444
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You