Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Global Variables shared between forms
Message
From
30/07/2004 12:09:35
 
General information
Forum:
ASP.NET
Category:
Other
Miscellaneous
Thread ID:
00929416
Message ID:
00929657
Views:
7
Thanks, I can use this code.

>>I agree with what you are saying but I don't understand how to do what you did in C#, in VB.
>
>
>Robert;
>
>I hope this gives you some ideas.
>
>Use a class to access data in VB dot NET
>
>In the code behind page:
>
>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
>
>
>My connection string is in my web.config file. The text box is used for testing to see how many records were in a dataset. You can fill drop down lists, grids, and text boxes using this methodology.
>
>Tom
Previous
Reply
Map
View

Click here to load this message in the networking platform