Public Sub LoadCategories() Try If cn.State = ConnectionState.Closed Then cn.Open() End If Dim sql As String = "Select Category from Categories ORDER BY Category Asc" Using ds As New DataSet Using da As New OleDb.OleDbDataAdapter(sql, cn) da.Fill(ds) End Using If ds.Tables(0).Rows.Count = 0 Then MsgBox("No categories were found.", MsgBoxStyle.Critical, "NO RECORDS!") Exit Sub End If For i As Integer = 0 To ds.Tables(0).Rows.Count - 1 Dim btn As New Button Try AddHandler btn.Click, AddressOf CategoryLoadClick btn.Width = 75 btn.Height = 50 btn.Text = ds.Tables(0).Rows(i)("Category").ToString Catch ex As Exception If Not btn Is Nothing Then btn.Dispose() End If MsgBox(ex.Message) End Try Next flowlayoutpanel.Controls.Add(btn) End Using Catch ex As Exception MsgBox(ex.Message) Finally cn.Close() End Try
Click
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)