Need help with N-Tier construction (Business layer)

Discussion in 'ASP .Net' started by Paul, Apr 19, 2006.

  1. Paul

    Paul Guest

    Hello, and thanks for listening.

    I have a Stored Procedure as follows:
    --
    PROCEDURE [PaoloPignatelli].[GetOneStoreByUserName3]

    -- Add the parameters for the stored procedure here

    @UserName Nvarchar (50)

    AS

    SELECT StoreID

    FROM dbo.Stores

    WHERE (StoreOwnerUserName = @UserName)

    --
    This works in SQL Server 2005; I input a UserName, and get a StoreID.
    ///
    In my Website, using the wizard, I created an
    XSD file called OneStoreByUserName, and on it a
    TableAdapter called GetOneStoreByUserName3DataTableTableAdapter, and a
    GetMethodName of
    GetStoreIDByUserName.
    (it appears as GetMethodName of GetStoreIDByUserName(@UserName,@StoreID) )

    When I see if things work so far, they do, I Preview Data, enter a value,
    and receive the correct StoreID.

    Now comes my question.
    How do I write a class (a business layer) that will allow me to access this
    data?
    I added a Class File to the App_Code folder and called it Stores.vb.
    I tried:
    Imports Microsoft.VisualBasic

    Imports System

    Imports System.Data

    Public Class Stores


    Public Function GetStoreID(ByVal UserName As String) As DataTable

    Dim StoreDB As New
    OneStoreByUserNameTableAdapters.GetOneStoreByUserName3DataTableTableAdapter

    Return StoreDB.GetStoreIDByUserName(UserName)

    End Function

    End Class

    ---

    No errors on page .... (but I know that means little...)

    Then on the aspx.vb page where I wish to consume the class I have

    ---------------

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
    Handles Me.Load

    Dim UserName As String = "Paolo1"

    Dim myStore As New Stores

    Label1.Text = myStore.GetStoreID(UserName).ToString()

    End Sub

    ---

    I get no errors, but when I view in browser, I also get in the label the
    text:

    GetOneStoreByUserName3DataTable

    and not the integer I was hoping for...



    How do I get the label to spit out the integer I need? Any and all help is
    appreciated,



    Paul

    Thanks.
     
    Paul, Apr 19, 2006
    #1
    1. Advertising

  2. in your line:

    Label1.Text = myStore.GetStoreID(UserName).ToString()

    note that GetStoreID returns a DataTable instance, not a string value. the
    ToString function of DataTable return the class name. you proably want to
    access a row and column in the datatable.


    -- bruce (sqlwork.com)





    "Paul" <> wrote in message
    news:5Kr1g.9$...
    > Hello, and thanks for listening.
    >
    > I have a Stored Procedure as follows:
    > --
    > PROCEDURE [PaoloPignatelli].[GetOneStoreByUserName3]
    >
    > -- Add the parameters for the stored procedure here
    >
    > @UserName Nvarchar (50)
    >
    > AS
    >
    > SELECT StoreID
    >
    > FROM dbo.Stores
    >
    > WHERE (StoreOwnerUserName = @UserName)
    >
    > --
    > This works in SQL Server 2005; I input a UserName, and get a StoreID.
    > ///
    > In my Website, using the wizard, I created an
    > XSD file called OneStoreByUserName, and on it a
    > TableAdapter called GetOneStoreByUserName3DataTableTableAdapter, and a
    > GetMethodName of
    > GetStoreIDByUserName.
    > (it appears as GetMethodName of GetStoreIDByUserName(@UserName,@StoreID) )
    >
    > When I see if things work so far, they do, I Preview Data, enter a value,
    > and receive the correct StoreID.
    >
    > Now comes my question.
    > How do I write a class (a business layer) that will allow me to access
    > this data?
    > I added a Class File to the App_Code folder and called it Stores.vb.
    > I tried:
    > Imports Microsoft.VisualBasic
    >
    > Imports System
    >
    > Imports System.Data
    >
    > Public Class Stores
    >
    >
    > Public Function GetStoreID(ByVal UserName As String) As DataTable
    >
    > Dim StoreDB As New
    > OneStoreByUserNameTableAdapters.GetOneStoreByUserName3DataTableTableAdapter
    >
    > Return StoreDB.GetStoreIDByUserName(UserName)
    >
    > End Function
    >
    > End Class
    >
    > ---
    >
    > No errors on page .... (but I know that means little...)
    >
    > Then on the aspx.vb page where I wish to consume the class I have
    >
    > ---------------
    >
    > Protected Sub Page_Load(ByVal sender As Object, ByVal e As
    > System.EventArgs) Handles Me.Load
    >
    > Dim UserName As String = "Paolo1"
    >
    > Dim myStore As New Stores
    >
    > Label1.Text = myStore.GetStoreID(UserName).ToString()
    >
    > End Sub
    >
    > ---
    >
    > I get no errors, but when I view in browser, I also get in the label the
    > text:
    >
    > GetOneStoreByUserName3DataTable
    >
    > and not the integer I was hoping for...
    >
    >
    >
    > How do I get the label to spit out the integer I need? Any and all help is
    > appreciated,
    >
    >
    >
    > Paul
    >
    > Thanks.
    >
    >
    >
    >
    >
    >
    >
     
    bruce barker \(sqlwork.com\), Apr 19, 2006
    #2
    1. Advertising

  3. Paul

    MSDN Guest

    Label1.Text = myStore.GetStoreID(UserName).Rows(0)("ColumnName").ToString

    "Paul" <> wrote in message
    news:5Kr1g.9$...
    > Hello, and thanks for listening.
    >
    > I have a Stored Procedure as follows:
    > --
    > PROCEDURE [PaoloPignatelli].[GetOneStoreByUserName3]
    >
    > -- Add the parameters for the stored procedure here
    >
    > @UserName Nvarchar (50)
    >
    > AS
    >
    > SELECT StoreID
    >
    > FROM dbo.Stores
    >
    > WHERE (StoreOwnerUserName = @UserName)
    >
    > --
    > This works in SQL Server 2005; I input a UserName, and get a StoreID.
    > ///
    > In my Website, using the wizard, I created an
    > XSD file called OneStoreByUserName, and on it a
    > TableAdapter called GetOneStoreByUserName3DataTableTableAdapter, and a
    > GetMethodName of
    > GetStoreIDByUserName.
    > (it appears as GetMethodName of GetStoreIDByUserName(@UserName,@StoreID) )
    >
    > When I see if things work so far, they do, I Preview Data, enter a value,
    > and receive the correct StoreID.
    >
    > Now comes my question.
    > How do I write a class (a business layer) that will allow me to access
    > this data?
    > I added a Class File to the App_Code folder and called it Stores.vb.
    > I tried:
    > Imports Microsoft.VisualBasic
    >
    > Imports System
    >
    > Imports System.Data
    >
    > Public Class Stores
    >
    >
    > Public Function GetStoreID(ByVal UserName As String) As DataTable
    >
    > Dim StoreDB As New
    > OneStoreByUserNameTableAdapters.GetOneStoreByUserName3DataTableTableAdapter
    >
    > Return StoreDB.GetStoreIDByUserName(UserName)
    >
    > End Function
    >
    > End Class
    >
    > ---
    >
    > No errors on page .... (but I know that means little...)
    >
    > Then on the aspx.vb page where I wish to consume the class I have
    >
    > ---------------
    >
    > Protected Sub Page_Load(ByVal sender As Object, ByVal e As
    > System.EventArgs) Handles Me.Load
    >
    > Dim UserName As String = "Paolo1"
    >
    > Dim myStore As New Stores
    >
    > Label1.Text = myStore.GetStoreID(UserName).ToString()
    >
    > End Sub
    >
    > ---
    >
    > I get no errors, but when I view in browser, I also get in the label the
    > text:
    >
    > GetOneStoreByUserName3DataTable
    >
    > and not the integer I was hoping for...
    >
    >
    >
    > How do I get the label to spit out the integer I need? Any and all help is
    > appreciated,
    >
    >
    >
    > Paul
    >
    > Thanks.
    >
    >
    >
    >
    >
    >
    >
     
    MSDN, Apr 19, 2006
    #3
  4. Paul

    Paul Guest

    Thanks, that did it!


    "MSDN" <> wrote in message
    news:...
    > Label1.Text = myStore.GetStoreID(UserName).Rows(0)("ColumnName").ToString
     
    Paul, Apr 19, 2006
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. et
    Replies:
    2
    Views:
    1,956
  2. dan
    Replies:
    25
    Views:
    1,377
    Uncle Bob (Robert C. Martin)
    Oct 28, 2003
  3. Nemisis
    Replies:
    1
    Views:
    515
    sloan
    Aug 22, 2006
  4. Dhananjay
    Replies:
    1
    Views:
    1,203
    sloan
    Dec 18, 2006
  5. SAL
    Replies:
    9
    Views:
    553
    Steven Cheng[MSFT]
    Jan 14, 2008
Loading...

Share This Page