Imports System.Data.SqlClient Imports System.Configuration Public Class Ch10Products Inherits System.ComponentModel.Component #Region " Component Designer generated code " Public Sub New(ByVal Container As System.ComponentModel.IContainer) MyClass.New() 'Required for Windows.Forms Class Composition Designer support Container.Add(Me) End Sub Public Sub New() MyBase.New() 'This call is required by the Component Designer. InitializeComponent() 'Add any initialization after the InitializeComponent() call End Sub 'Component overrides dispose to clean up the component list. Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean) If disposing Then If Not (components Is Nothing) Then components.Dispose() End If End If MyBase.Dispose(disposing) End Sub 'Required by the Component Designer Private components As System.ComponentModel.IContainer 'NOTE: The following procedure is required by the Component Designer 'It can be modified using the Component Designer. 'Do not modify it using the code editor. Private Sub InitializeComponent() End Sub #End Region Dim CS As String = ConfigurationSettings.AppSettings("CS") ' use the connection string below if you did not use an application variable ' Dim CS As String = _ ' "user id=sa;data source=(local)\NetSDK;" & _ ' "persist security info=True;" & _ ' "initial catalog=Ch10TaraStoreSQL;" & _ ' "password=password" Dim SqlConnection1 As New SqlConnection(CS) Public Function GetCat() As SqlDataReader SqlConnection1.Open() Dim objCM1 As SqlCommand objCM1 = New SqlCommand("SELECT * FROM Categories", SqlConnection1) objCM1.CommandType = CommandType.Text Dim objDR1 As SqlDataReader objDR1 = objCM1.ExecuteReader(CommandBehavior.CloseConnection) Return objDR1 End Function Public Function GetSubCats(ByVal CatID As Integer) As SqlDataReader SqlConnection1.Open() Dim objCM2 As SqlCommand Dim mySQL As String = "SELECT * FROM SubCategories WHERE CategoryID = " & CatID objCM2 = New SqlCommand(mySQL, SqlConnection1) objCM2.CommandType = CommandType.Text Dim objDR2 As SqlDataReader objDR2 = objCM2.ExecuteReader(CommandBehavior.CloseConnection) Return objDR2 End Function Public Function GetProducts(ByVal SubCatID As Integer) As SqlDataReader SqlConnection1.Open() Dim objCM3 As SqlCommand Dim mySQL As String = "SELECT * FROM Products WHERE SubCategoryID = " & SubCatID objCM3 = New SqlCommand(mySQL, SqlConnection1) objCM3.CommandType = CommandType.Text Dim objDR3 As SqlDataReader objDR3 = objCM3.ExecuteReader(CommandBehavior.CloseConnection) Return objDR3 End Function Public Function GetProduct(ByVal ProdID As Integer) As SqlDataReader SqlConnection1.Open() Dim objCM4 As SqlCommand Dim mySQL As String = "SELECT * FROM Products WHERE ProductID = " & ProdID objCM4 = New SqlCommand(mySQL, SqlConnection1) objCM4.CommandType = CommandType.Text Dim objDR4 As SqlDataReader objDR4 = objCM4.ExecuteReader(CommandBehavior.CloseConnection) Return objDR4 End Function End Class