Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Creating a DataAccess Layer
Message
De
26/07/2002 10:21:09
 
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Divers
Thread ID:
00682972
Message ID:
00682981
Vues:
30
Kirk,

I'd probably have to dig a little deeper to find your exact problem (especially since I use C#, not VB), but right off the top I have a suggestion. It seems like you're connecting to a SQL Server ... you should not be using the OleDb.OleDbConnection. You should be using the SqlConnection in the System.Data.SqlClient namespace. This may be contributing to your problem.

~~Bonnie


>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
>
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform