Avatar billede disco_keld Nybegynder
24. april 2003 - 15:53 Der er 1 kommentar og
1 løsning

Instantiere en serviced component???

For at jeg kan instantiere en Serviced Component, skal jeg da lave et Public Interface eller hvordan?

Min kode kommer her

Menu.vb er serviced componenten:

<Assembly: ApplicationName("SuperMarket")>
<Assembly: ApplicationActivation(ActivationOption.Library)>
<Assembly: AssemblyKeyFile("KeyFile.snk")>

Namespace Supermarket

    'Indicate that this class uses Object Pooling, Transactions are Required, and has an Object Construction String
    <ObjectPooling(Enabled:=True, MinPoolSize:=2, MaxPoolSize:=10, CreationTimeout:=20000), Transaction(TransactionOption.Required), JustInTimeActivation(True), ConstructionEnabledAttribute(Default:="data source=MAINFRAME;initial catalog=Supermarket;password=password;persist security info=True;user id=sa;workstation id=MAINFRAME;packet size=4096")> _
    Public Class Menu
        Inherits ServicedComponent

        Private c_sConnectionString As String
        Private c_oPooledDataSet As DataSet

        Public Sub New()

        End Sub

        <AutoComplete(True)> _
        Public Function GetMenuItems() As DataSet
            Dim oCommand As New SqlCommand()
            Dim oDataAdapter As New SqlDataAdapter()
            c_oPooledDataSet = New DataSet()

            With oCommand
                .CommandText = "sp_GetMenuItems"
                .CommandType = CommandType.StoredProcedure
                .Connection = GetConnection()
            End With

            With oDataAdapter
                .SelectCommand = oCommand
                .Fill(c_oPooledDataSet, "Menu")
            End With

            Return c_oPooledDataSet
        End Function

        Private Function GetConnection() As SqlConnection
            Dim oConnection As SqlConnection
            Try
                oConnection = New SqlConnection(c_sConnectionString)
                oConnection.Open()
                Return oConnection
            Catch ex As Exception
                Throw New Exception()
            End Try
        End Function

    End Class

End Namespace

---------------------------------------------------------------------------------
User Control hvor jeg prøver at instantiere den serviced component:

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            If Not Page.IsPostBack Then
                Dim listIndex As String = Request.Params("tabIndex")

                If Not listIndex Is Nothing Then
                    dlMenu.SelectedIndex = CInt(listIndex)
                End If

                Dim oMenu As New Supermarket. ?????????????
                dlMenu.DataSource = oMenu.GetMenuItems()
                dlMenu.DataBind()
            End If
        End Sub

Hvis der er andre bemærkelsesværdige ting i min kode så hold jer endelig ikke tilbage!

:-D

mvh

DK
Avatar billede disco_keld Nybegynder
04. maj 2003 - 21:31 #1
lukker
Avatar billede burningice Nybegynder
04. maj 2003 - 21:37 #2
Dim oMenu As New Supermarket.Menu() vel, da Menu jo er navnet på din klasse, og din konstructor ikke tager nogle argumenter.
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Kurser inden for grundlæggende programmering

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester