?
Solved

http://www.experts-exchange.com/Programming/Programming_Languages/Dot_Net/ASP_DOT_NET/Q_21400322.html

Posted on 2005-04-24
8
Medium Priority
?
465 Views
Last Modified: 2010-04-07
http://www.experts-exchange.com/Programming/Programming_Languages/Dot_Net/ASP_DOT_NET/Q_21400322.html

After a long struggle,

I have managed to progress a bit further., i have split my biz layer into two groups (BL AND DL)
BL CODE IS THIS
================
Imports Orbits.Data

Namespace BusinessLogic
    Public Class Customers
        Private CustomersDL As New Data.CustomersDL
        Public Function Add(ByVal CustomerName As String)
            'this is adding Supplier details
            Add = CustomersDL.AddCustomer(CustomerName)
            Return Add
        End Function
    End Class
End Namespace

===================
DL CODE IS THIS

===============
Imports DataAccess
Namespace Data
    Public Class CustomersDL
        ' Private connString As String = CompanyConfig.CompanySetting.MainConnectionString
        Private DL As New SQLProvider(connString)
        Public Function AddCustomer(ByVal CustomerName As String)
            'Calls the Stored Procedure which adds New Customers
            Dim sqlparams As New ArrayList
            Dim bnInserted As Boolean
            Dim ad As Integer
            'sets the input parameters
            sqlparams.Add(DL.AddParameter("@SupplierName", "SqlDbType.NvarChar", 50, CustomerName, ParameterDirection.Input))
                      ad = sqlparams.Add(DL.AddParameter("RETURN_VALUE", "SqlDbType.Integer", 1, bnInserted, ParameterDirection.ReturnValue))
            'calls the stored Procedure
            AddCustomer = DL.ExecuteStoredProc("InsertSuppliers", sqlparams, True)
            Return AddCustomer
        End Function
    End Class
End Namespace
=================


However, in my CustomerDL.vb




i keep getting this error

Type 'SQLProvider' is not defined. ========

===Private DL As New SQLProvider(connString)===

Does anyone know the reason,  OR A WAY ROUND THIS?

THANKS GUYS

It seems to work perfectly at work.
0
Comment
Question by:SirReadAlot
  • 3
  • 3
  • 2
8 Comments
 
LVL 26

Assisted Solution

by:Rejojohny
Rejojohny earned 1000 total points
ID: 13853464
>>Private DL As New SQLProvider(connString)

What is SQLProvider? In the dataaccess namespace u have imported i couln't find any class with that name?
0
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 1000 total points
ID: 13853890
I think the line:

    Private DL As New SQLProvider(connString)

Should actually be:

    Private DL As New SQLConnection(connString)



Hope this helps.
0
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 13853895
Unless of course its your own class, which is supposed to reside in the "DataAccess" namespace. If this is the case then it would appear that there is settings problem.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 26

Expert Comment

by:Rejojohny
ID: 13853955
carl_tawn,
that is what i too thought .. but then he has created his own DL ..
so it must have been
Private DL As New Database(connString)

But then i couldn't find any constructor to the class DataAccess which accepts a connection string .. infact no constructor at all ...(i.e. in the code .. in the link provided)
0
 

Author Comment

by:SirReadAlot
ID: 13853980
hi guys,

was just following some examples, would there be any way around this







0
 

Author Comment

by:SirReadAlot
ID: 13853982
this is my data access code

Imports System.Data.SqlClient
Imports System
'Imports System.Web.Caching
Imports System.Reflection


Namespace DataAccess
    '***********************************************************
    'This class enables the datalayer to communicate with the database
    'This datalayer is buuilt purely for  SQL Server
    '**********************************************************
    Public Class SQLProvider
        Implements IDisposable

        Private mDs As Dataset
        Private WithEvents mAdapter As SqlDataAdapter
        Private mConn As SqlConnection
        Private mReader As SqlDataReader
        Private mConnString As String
        Private Const mConfigFilePart As String = "ConnectionString"

        Public Property ConnectionString() As String
            'generally retrived from a config file
            Get
                Return mConnString
            End Get
            Set(ByVal Value As String)
                mConnString = Value
            End Set
        End Property

        '--> Return Reader
        Public ReadOnly Property Reader() As SqlDataReader
            Get
                Return mReader
            End Get
        End Property


        '--> Return Adapter
        Public ReadOnly Property Adapter() As SqlDataAdapter
            Get
                Return mAdapter
            End Get
        End Property

        '--> Return Dataset
        Public ReadOnly Property Dataset() As Dataset
            Get
                Return mDs
            End Get
        End Property

        '--> Active Connection Object
        Public ReadOnly Property Connection() As SqlConnection
            Get
                Return mConn
            End Get
        End Property

        '--> Constructor
        Public Sub New()
            MyBase.new()
            mConnString = Nothing  'ConfigurationSettings.AppSettings(mConfigFilePart)
        End Sub
        Public Sub New(ByVal ConString As String)
            MyBase.new()
            mConnString = ConString
        End Sub

        Public Sub OpenDB()
            'opens connection with DB
            mConn = New SqlConnection
            mConn.ConnectionString = mConnString
            mConn.Open()

        End Sub

        Public Sub CloseDB()
            'closes connection with DB
            If Not mConn Is Nothing Then
                If mConn.State = ConnectionState.Open Then
                    mConn.Close()
                End If
            End If
        End Sub



        '--> Destructor
        Public Sub Dispose() Implements System.IDisposable.Dispose
            'kills connection with DB
            Call CloseDB()
        End Sub

        Public Overridable Function ReturnDataSet(ByVal sp As String, ByVal tableName As String) As Dataset
            'returns dataset be executing stored procedures
            Dim mDs = New DataSet
            Try
                OpenDB()
                Dim Cmd = New SqlCommand(sp, mConn)
                Cmd.CommandType = CommandType.StoredProcedure
                Dim adp As New SqlDataAdapter(Cmd)
                adp.Fill(mDs, tableName)
            Catch ex As SqlException
                Throw New ArgumentException(ex.Message.ToString())
            Finally
                Dispose()
            End Try
            Return mDs
        End Function


        Public Overridable Sub ExecuteStoredProc(ByVal spName As String, ByVal sqlparams As ArrayList)
            'executes Stored procedure with parameters
            Try
                OpenDB()
                Dim cmd As New SqlCommand(spName, mConn)
                cmd.CommandType = CommandType.StoredProcedure
                Dim p As SqlParameter
                For Each p In sqlparams
                    cmd.Parameters.Add(p)
                Next
                cmd.ExecuteNonQuery()
            Catch ex As SqlException
                Throw New ArgumentException(ex.Message.ToString())
            Finally
                'CloseDB()
                Dispose()
            End Try
        End Sub
        Public Overridable Function ExecuteStoredProc(ByVal spName As String, ByVal sqlparams As ArrayList, ByVal ReturnValue As Boolean) As Object
            'executes Stored procedure with parameters
            Try
                OpenDB()
                Dim cmd As New SqlCommand(spName, mConn)
                cmd.CommandType = CommandType.StoredProcedure

                Dim p As SqlParameter
                For Each p In sqlparams
                    cmd.Parameters.Add(p)
                Next
                cmd.ExecuteNonQuery()
                ExecuteStoredProc = cmd.Parameters("RETURN_VALUE").Value
            Catch ex As SqlException
                Throw New ArgumentException(ex.Message.ToString())
            Finally
                'CloseDB()
                Dispose()
            End Try
        End Function
        Public Overridable Sub ExecuteStoredProc(ByVal spName As String)
            'executes Stored procedure
            Try
                OpenDB()
                Dim cmd As New SqlCommand(spName, mConn)
                cmd.CommandType = CommandType.StoredProcedure
                cmd.ExecuteNonQuery()
            Catch ex As SqlException
                Throw New ArgumentException(ex.Message.ToString())
            Finally
                Dispose()
            End Try
        End Sub



        Public Overridable Function ReturnDataSet(ByVal sqlparams As ArrayList, ByVal spName As String, ByVal tableName As String) As Dataset
            'returns dataset by executes Stored procedure with parameters
            Dim mDs = New DataSet
            Try
                OpenDB()
                Dim Cmd = New SqlCommand(spName, mConn)
                Cmd.CommandType = CommandType.StoredProcedure
                Dim p As SqlParameter
                For Each p In sqlparams
                    Cmd.Parameters.Add(p)
                Next
                Dim adp As New SqlDataAdapter(Cmd)
                adp.Fill(mDs, tableName)
            Catch ex As SqlException
                Throw New ArgumentException(ex.Message.ToString())
            Finally
                Dispose()
            End Try
            Return mDs
        End Function
        Public Overridable Function ReturnDataSet(ByVal SQL As String) As Dataset
            'returns dataset by executes Stored procedure with parameters
            Dim mDs = New DataSet
            Try
                OpenDB()
                Dim Cmd = New SqlCommand(SQL, mConn)
                Cmd.CommandType = CommandType.Text
                ' Dim p As SqlParameter
                'For Each p In sqlparams
                '    Cmd.Parameters.Add(p)
                'Next
                Dim adp As New SqlDataAdapter(Cmd)
                adp.Fill(mDs, "Clients")
            Catch ex As SqlException
                Throw New ArgumentException(ex.Message.ToString())
            Finally
                Dispose()
            End Try
            Return mDs
        End Function

        Public Overridable Function ReturnSingleValue(ByVal sqlparams As ArrayList, ByVal spName As String) As Object
            'returns single value by executing stored provedure with parameters
            Dim obj = New Object
            Try
                OpenDB()
                Dim Cmd = New SqlCommand(spName, mConn)
                Cmd.CommandType = CommandType.StoredProcedure
                Dim p As SqlParameter
                For Each p In sqlparams
                    Cmd.Parameters.Add(p)
                Next
                Return Cmd.ExecuteScalar
            Catch ex As SqlException
                Throw New ArgumentException(ex.Message.ToString())
            Finally
                Dispose()
            End Try

        End Function
        Public Overridable Function ReturnSingleValue(ByVal sql As String) As Object
            'returns single value by executing stored provedure with parameters
            Dim obj = New Object
            Try
                OpenDB()
                Dim Cmd = New SqlCommand(sql, mConn)
                Return Cmd.ExecuteScalar
            Catch ex As SqlException
                Throw New ArgumentException(ex.Message.ToString())
            Finally
                Dispose()
            End Try

        End Function

        Public Function OpenReader(ByVal strSQL As String, ByVal sqlParams As ArrayList) As Object
            'Opens datareader
            Dim obj As Object
            OpenDB()
            Dim cmd As New SqlCommand(strSQL, mConn)
            cmd.CommandType = CommandType.StoredProcedure
            Dim p As SqlParameter
            For Each p In sqlParams
                cmd.Parameters.Add(p)
            Next
            If Not mReader Is Nothing Then mReader = Nothing
            mReader = cmd.ExecuteReader
            While mReader.Read()
                If IsDBNull(mReader.GetValue(0)) = True Then
                    obj = CObj(String.Empty)
                Else
                    obj = mReader.GetValue(0)
                End If
            End While

            Return obj
        End Function

        Public Overridable Function executeDataReader(ByVal spName As String, ByVal sqlParams As ArrayList) As Object
            'executes reader to return an object, ie one value
            Dim obj As Object
            Try
                OpenDB()
                Dim cmd As New SqlCommand(spName, mConn)
                cmd.CommandType = CommandType.StoredProcedure
                Dim p As SqlParameter
                For Each p In sqlParams
                    cmd.Parameters.Add(p)
                Next
                If Not mReader Is Nothing Then mReader = Nothing
                mReader = cmd.ExecuteReader
                While mReader.Read()
                    If IsDBNull(mReader.GetValue(0)) = True Then
                        obj = Nothing
                    Else
                        obj = mReader.GetValue(0)
                    End If
                End While
            Catch ex As SqlException
                Throw ex
            Finally
                Dispose()
            End Try
            Return obj
        End Function

        Public Overridable Function exDataReader(ByVal spName As String, ByVal sqlParams As ArrayList) As Object
            'executes reader to return an object, ie one value
            Dim obj As Object
            Try
                OpenDB()
                Dim cmd As New SqlCommand(spName, mConn)
                cmd.CommandType = CommandType.StoredProcedure
                Dim p As SqlParameter
                For Each p In sqlParams
                    cmd.Parameters.Add(p)
                Next
                If Not mReader Is Nothing Then mReader = Nothing
                obj = cmd.ExecuteReader
            Catch ex As SqlException
                Throw ex
            Finally
                Dispose()
            End Try
            Return obj
        End Function

        Public Overridable Function AddParameter(ByVal sParameterName As String, ByVal lSqlType As String, ByVal iSize As Integer, ByVal sValue As String, ByVal iDirection As Integer) As SqlParameter
            'Add parameters to stored procedure
            If lSqlType = "SqlDbType.Bit" Then
                sValue = CStr(sValue)
            End If
            Dim sqlparam = New SqlParameter(sParameterName, lSqlType)
            sqlparam.Direction = iDirection
            If Not iDirection = ParameterDirection.Output Then
                sqlparam.Value = sValue
            End If

            Return sqlparam
        End Function

        Function Sort(ByVal sortby As String, ByVal ds As Dataset, ByVal tableName As String) As DataView
            'sorts a dataset and returns as a dataview
            Dim dv As DataView
            Try
                dv = ds.Tables(tableName).DefaultView
                dv.Sort = sortby
            Catch ex As SqlException
                Throw ex
            End Try
            Return dv
        End Function
    End Class
End Namespace



0
 
LVL 26

Expert Comment

by:Rejojohny
ID: 13856364
r u still getting the error?
0
 

Author Comment

by:SirReadAlot
ID: 13862466
fixed it!!
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question