Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Creating a DataAccess Layer
Message
General information
Forum:
ASP.NET
Category:
Other
Miscellaneous
Thread ID:
00682972
Message ID:
00683008
Views:
38
This message has been marked as the solution to the initial question of the thread.
Hi Kirk,

The reason why your code isn't working is you never instantiate the DataObjectVB class. Change the line of code that is "Dim"ming your oDataConn variable to the following:
Dim oDataConn As New DataObjectVB()
You need to create an instance of the class before calling any of it's methods.

>I've never created a DataAccess layer and am attempting to do one now before I get to far along. So I thought I would
>start off my creating a DataObjectVB class, with multiple functions. The first function I am trying to build is the
>getConnection. This would return me a oledbConnection object. But when I try to run my code I get a null exeception error. I'm hoping someone might spot what I am missing, or have an example of a datalayer class. Below is the code:
>
>
>'Login Button Code
>Dim oDataConn As DataObjectVB
>Dim lcSQL As String
>Dim oConn As OleDb.OleDbConnection
>Dim goView As Data.DataView
>Dim iRecords As Integer
>Dim cStatusText As String
>Dim docID As String
>
>'Get the connection string and sql statement
>
>docID = txtUserName.Text
>Session("UserID") = docID
>
>lcSQL = "Select rtrim(lastname)+', '+rtrim(firstname) as docname, isnull(password,' ') as password, isnull(logincount,0) as logincount, isnull(lastlogin, ' ') as lastlogin, remaccess,remschedule from coper where isactive=1 and PerTypeID=1 and coPerID=" & docID
>
>
>oConn = oDataConn.GetConnection()
>
>
>Last Line causes error:
>-- Error Message: NullReferenceException: Object reference not set to an instance of an object
>
>Code for oDataConn.GetConnection()
>
>
>    Public Function GetConnection() As OleDb.OleDbConnection
>        Dim lcConnectionString As String
>        lcConnectionString = "provider=sqloledb.1;server=cqi-termserv;uid=ctore;pwd=cqi$$;database=ctore"
>
>        Dim lcSQL As String
>        Dim oConn As OleDb.OleDbConnection
>
>        oConn = VFPToolkit.vfpData.SqlConnect(lcConnectionString)
>
>        Return oConn
>
>    End Function
>
-----------------------------------------

Cathi Gero, CPA
Prenia Software & Consulting Services
Microsoft C# / .NET MVP
Mere Mortals for .NET MVP
cgero@prenia.com
www.prenia.com
Weblog: blogs.prenia.com/cathi
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform