' Method that Fills the WinDataSource with Data from our SQL Server. This can
' be scaled so that you have Overloads that may take Keys, Search Criteria and Sort Order
Public Sub FillData()
Dim cn As New SqlConnection(_cn)
Dim cm As SqlCommand = cn.CreateCommand()
cm.CommandText = "SELECT CategoryID,CategoryName,Description," + _
"Picture FROM Categories ORDER BY CategoryName ASC"
cm.CommandType = CommandType.Text
cn.Open()
Dim dr As SqlDataReader = cm.ExecuteReader(CommandBehavior.Default)
Dim rowCount As Integer
While dr.Read = True
rowCount += 1
MyBase.Rows.Add(New Object() {dr("CategoryID"), _
dr("CategoryName"), _
dr("Description"), _
dr("Picture")})
End While
MyBase.Rows.SetCount(rowCount)
dr.Close()
cn.Dispose()
End Sub