943,609 Members | Top Members by Rank

Ad:
  • VB.NET Discussion Thread
  • Unsolved
  • Views: 1654
  • VB.NET RSS
Sep 25th, 2008
0

How to retriev data frm DB in datacombo

Expand Post »
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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
asmit1987 is offline Offline
22 posts
since Sep 2008
Sep 25th, 2008
0

Re: How to retriev data frm DB in datacombo

VB.NET Syntax (Toggle Plain Text)
  1. Private Sub ReadData()
  2. Dim i As Integer
  3.  
  4. con.ConnectionString = ("Provider = Microsoft.JET.OLEDB.4.0;Data Source= D:\Only Me\Authors.mdb")
  5. Try
  6.  
  7. cmdOle = con.CreateCommand
  8. cmdOle.CommandText = "SELECT * FROM Authors "
  9. da.SelectCommand = cmdOle
  10. da.Fill(dsOle, "Authors")
  11. dtOle = dsOle.Tables("Authors")
  12. For i = 0 To dtOle.Rows.Count - 1
  13. cmbAuthor.Items.Add(dtOle.Rows(i).Item(1))
  14. Next
  15.  
  16. Catch ex As Exception
  17. MsgBox("Error: " & ex.Source & ": " & ex.Message, MsgBoxStyle.OKOnly, "Koneksi Error !!")
  18. End Try
  19. con.Close()
  20. 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))
Reputation Points: 1182
Solved Threads: 392
Posting Sensei
Jx_Man is offline Offline
3,138 posts
since Nov 2007
Sep 28th, 2008
0

Re: How to retriev data frm DB in datacombo

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.....
Reputation Points: 10
Solved Threads: 0
Newbie Poster
asmit1987 is offline Offline
22 posts
since Sep 2008
Sep 29th, 2008
0

Re: How to retriev data frm DB in datacombo

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"))
Last edited by Jx_Man; Sep 29th, 2008 at 12:14 am.
Reputation Points: 1182
Solved Threads: 392
Posting Sensei
Jx_Man is offline Offline
3,138 posts
since Nov 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in VB.NET Forum Timeline: help with code.
Next Thread in VB.NET Forum Timeline: how to create setip in vb.net





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC