Private Sub FillCbo(ByVal theSQL As String)
Dim dr As DataRow
Dim dt As DataTable
Dim cmd As New OleDbCommand
Dim ds As New DataSet
Dim da As New OleDb.OleDbDataAdapter
pCat.Items.Clear()
sql = theSQL
'sql = "Select CategoryID, CategoryName from Category Order by CategoryName ASC"
Try
With da
.TableMappings.Add("Table", "Category")
cmd = New System.Data.OleDb.OleDbCommand(sql, con)
.SelectCommand = cmd
.Fill(ds)
.Dispose()
End With
ds.AcceptChanges()
dt = ds.Tables.Item(0)
ds.Dispose()
pCat.Text = ""
pCat.Items.Clear()
pCat.BeginUpdate()
For Each dr In dt.Rows
pCat.Items.Add(dr("CategoryName").ToString)
Next
pCat.EndUpdate()
Catch ex As Exception
MsgBox("There was an error accessing Categories: " & vbCrLf & ex.Message, MsgBoxStyle.OkOnly, "Error!")
End Try
End Sub
|