First go to following link
Secure connection and easy transaction handling in .Net
to understand the logic for the connection
and to get the idea of what objDB means.
Just create a objDB class from the above link provided and use the following code
The follwoing are the two ways of loading the data in the combobox or drop down list in
.Net Application:
Private Sub LoadCats()
Dim objdb As New clsObjDB
Dim ds As New DataSet
Dim str As String
cboCats.Items.Clear()
str = "Select * from cat order by catID desc"
ds = objdb.getDataset(str)
Dim dt As DataTable
dt = ds.Tables(0)
For Each row As DataRow In dt.Rows
cboCats.ValueMember = row("CatID")
cboCats.Items.Add(row("CatName"))
Next
End Sub
In the above function I have used Data row to go through the each every record
of the datbase
but in the following example i have directly specified the data source to the
combo box control and determined which value to display.
Private Sub LoadCats1()
Dim objdb As New clsObjDB
Dim ds As New DataSet
Dim str As String
cboCats.Items.Clear()
str = "Select * from cat order by catID desc"
ds = objdb.getDataset(str)
cboCats.DataSource = ds.Tables(0)
cboCats.DisplayMember = "CatName"
End Sub
No comments:
Post a Comment