>Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load > 'Put user code to initialize the page here > > If Not IsPostBack Then > Call BindCustomers() > End If > End Sub > > Public Sub BindCustomers() > > dgCustomers.DataSource = CustomersDB.GetCustomers() > dgCustomers.DataBind() > > txtRecordsFound.Text = dgCustomers.DataSource.Tables("Customers").Rows.Count > > End Sub >>Create a Class called CustomersDB (or what every you like) so all your forms can access data from one source:
>Imports System.Data.SqlClient > >Public Class CustomersDB > Private Shared Function connection() As SqlConnection > 'Public Shared Function connection() As SqlConnection > Dim sConnectionString As String > sConnectionString = _ > ConfigurationSettings.AppSettings("ConnectionString") > Return New SqlConnection(sConnectionString) > > End Function > > Public Shared Function GetCustomers() As DataSet > Dim sSelect As String = "select * from Customers" > Dim cmdCategories As New SqlCommand(sSelect, Connection) > Dim daCustomers As New SqlDataAdapter() > daCustomers.SelectCommand = cmdCategories > Dim dsCustomers As New DataSet() > daCustomers.Fill(dsCustomers, "Customers") > Return dsCustomers > ' > End Function > > Public Shared Function GetAllSpCustomers() As DataSet > > Dim daCustomer As New SqlDataAdapter() > daCustomer.SelectCommand = New SqlCommand() > daCustomer.SelectCommand.Connection = connection() > daCustomer.SelectCommand.CommandText = "GetAllCustomers" > daCustomer.SelectCommand.CommandType = CommandType.StoredProcedure > > Dim ds As New DataSet() > daCustomer.Fill(ds, "Customer") > > Return ds > > End Function > > > Public Shared Function GetOneSpCustomer(ByVal customerID As String) As DataSet > > Dim daCustomer As New SqlDataAdapter() > > Dim customerParam1 As New SqlParameter _ > ("@CustomerID", SqlDbType.NChar, 5) > > customerParam1.Direction = ParameterDirection.Input > > customerParam1.Value = customerID > > daCustomer.SelectCommand = New SqlCommand() > daCustomer.SelectCommand.Connection = connection() > > daCustomer.SelectCommand.CommandText = "GetOneCustomer" > daCustomer.SelectCommand.CommandType = CommandType.StoredProcedure > > daCustomer.SelectCommand.Parameters.Add(customerParam1) > > Dim ds As New DataSet() > daCustomer.Fill(ds, "Customer") > > Return ds > > End Function > > > >End Class >>