erikkl2000 0 Newbie Poster

Hello,

This is my first go at implementing an interface for a connection, reader, ect.. and it is also my first go at a three tier design,Although i have been studing this for some time now tring to put all of these pieces togeather. I feel like i am getting to a point that i can comfortably work with this type of suggest design.

I am having trouble connecting to the database. The error that i am getting says that the object is not set to an instant of an object,, ( ok so i might say hey,, i kown what this is, but with the interfaces there is no way to just say, dim my iDBC as new idbconnection)'' Can someone please look at my code and help me pinpoint what needs to be corrected. Not just the connection but the rest of the implementation.It would really help me out alot, because i am into new waters.
===================

*** this is what i have created to test with so that once i can get going with this then i can move forward with the real stuff.. I would be so greatful to have developers that can point out a better way of strongly typeing my database here.. One of the reasons that i want to learn implementing this this way is because from what i understand this is the correct way(maybe not exactly the way that i have it ).. Any help at all would be great!!!


From the form page......................
-------------------------------------------------------------------
Imports DA = SuperCenter.DataAccess.Blinds

Namespace SuperCenter.Web

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
GetNumbers()
End Sub
'
Public Sub GetNumbers()

Dim pk As Int32 = 3
With New DA
ddl.DataSource = .GetNumbers(Request.QueryString("pk"))
ddl.DataBind()
End With
End Sub

End Class
End Namespace
============================================================

===============================================
dataaccess
=============================================

Imports System.Data.SqlClient
Imports DATA = SuperCenter.Data


Namespace SuperCenter.DataAccess


Public Class Blinds

Private _Datareader As IDataReader
Private _cnn As IDbConnection
Const DATABASE = "Data Source=Desktop; Initial Catalog=TEST; Trusted_Connection=True"
'
Public Sub New()

With _cnn

.ConnectionString = DATABASE **** My error is right here****

End With
End Sub
'
Public Function GetNumbers(ByVal pk As Int32) As Data.Blinds
'
GetNumbers = SharedAccess("BlindGetNumbers", "@pk", pk)
End Function
'
Private Function SharedAccess(ByVal BlindSprocName As String, _
ByVal parmName As String, _
ByVal parmvalue As Int32) As Data.Blinds

Dim B As Data.Blinds
Dim BL As New Data.BlindList

Dim cmd As IDbCommand
With cmd
.CommandType = CommandType.StoredProcedure
.CommandText = BlindSprocName
Dim ipram As IDataParameter
With ipram
.DbType = DbType.Int32
.ParameterName = parmName
.Value = parmvalue
End With
.Parameters.Add(ipram)
End With

_cnn.Open()
_Datareader = cmd.ExecuteReader
While _Datareader.Read

BL.add(New Data.Blinds(_Datareader("Numbers")))

End While
_cnn.Close()
_Datareader.Dispose()
_Datareader.Close()
'
If _cnn.State = ConnectionState.Open Then
_cnn.Close()
If _Datareader.IsClosed = False Then
_Datareader.Close()
_Datareader.Dispose()
End If
End If

End Function
'

End Class
End Namespace

=======================================================

Property page---------------------------
================================================


Namespace SuperCenter.Data

Public Class Blinds

Private _Width As String
Private _Tall As String
Private _Numbers As String
Private _Colors As String
Private _Extras As String

Public Sub New()

End Sub
Public Sub New(ByVal Numbers As String)
_Numbers = Numbers
End Sub
'
Public Sub New(ByVal Width As String, _
ByVal Tall As String, _
ByVal Numbers As String, _
ByVal Colors As String, _
ByVal Extras As String)

_Width = Width
_Tall = Tall
_Numbers = Numbers
_Colors = Colors
_Extras = Extras

End Sub
'
Public Property Width() As String
Get
Return _Width
End Get
Set(ByVal Value As String)
_Width = Value
End Set
End Property
'
Public Property Tall() As String
Get
Return _Tall
End Get
Set(ByVal Value As String)
_Tall = Value
End Set
End Property
'
Public Property Numbers() As String
Get
Return _Numbers
End Get
Set(ByVal Value As String)
_Numbers = Value
End Set
End Property
'
Public Property Colors() As String
Get
Return _Colors
End Get
Set(ByVal Value As String)
_Colors = Value
End Set
End Property
'
Public Property Extras() As String
Get
Return _Extras
End Get
Set(ByVal Value As String)
_Extras = Value
End Set
End Property

End Class
End Namespace
===================================================
CollectionBase page
==============================================

Namespace SuperCenter.Data

Public Class BlindList : Inherits CollectionBase
'
Public Sub New()

End Sub
'
Public Function add(ByVal blind As Blinds) As Int32
Return Me.add(blind)
End Function
'
Default Public ReadOnly Property item(ByVal index As Int32)
Get
Return CType(item(index), Blinds)
End Get
End Property
'

End Class
End Namespace

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.