473,388 Members | 1,322 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

Class to handle DB connections

Hi All,

I'm trying to create a class to connect/disconnect a database. Code I have
so far is below, problem is that the closeconn function gives me an error -
Name 'SPDOleDbConnection' is not declared.

Also getting the same problem in my code where I want to use the connection
(also shown below)

Would appreciate it if anyone has any ideas - Surely I dont have to repeat
this code everytime I open/close a connection! :)

Regards,
Simon.
Code to open/close connection
========================
Public Class DataBase

Public Function OpenConn() As System.Data.OleDb.OleDbConnection
Dim configurationAppSettings As
System.Configuration.AppSettingsReader = New
System.Configuration.AppSettingsReader
Dim SPDOleDbConnection As New OleDb.OleDbConnection
SPDOleDbConnection.ConnectionString =
CType(configurationAppSettings.GetValue("OleDbConn ection1.ConnectionString",
GetType(System.String)), String)
SPDOleDbConnection.Open()
End Function
Public Function CloseConn() As System.Data.OleDb.OleDbConnection
SPDOleDbConnection.Close()
End Function

End Class

Code where I want to use the connection
===============================
Dim myCommand As New System.Data.OleDb.OleDbCommand("SELECT Country FROM
Countries WHERE CountryID = " & CountryID, SPDOleDbConnection)
Dim myReader As System.Data.OleDb.OleDbDataReader =
myCommand.ExecuteReader(CommandBehavior.CloseConne ction)
While myReader.Read()
Return myReader.GetString(0)
End While
myReader.Close()
Nov 18 '05 #1
0 826

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: news | last post by:
Well, I wrote my first PHP class today. Yeah! But to get it to work, in each function within the class I have to repeat the database connection lines, and that just seems redundant; there has to...
3
by: Brad Navarro | last post by:
OK, I may be asking for the impossible, but I'll give it a shot: For a case like this: using System.Data.SqlClient; abstract class Base { private SqlConnection DBConnect; Base(string...
4
by: Gav | last post by:
Hi all, This may not be the best way to do things I'm not sure... however I have created a class that handles all the database calls, I didn't want to keep having to create connections to the...
1
by: quest | last post by:
My webserver application (a http handler) accepts a sequence of requests from client. Each request requires an access to database (password/username supplied in the request). I am looking at...
1
by: Bruce W.1 | last post by:
I want to put a live connection in a web page to periodically updated data. When the data changes, the server notifys the client and gives the new data. The client does not regularly refresh the...
5
by: Dave Johnson | last post by:
Working on Asp.net with access database backend,a serious Question in the Class design phase, for accessing the database; Which is Better to make a Connection Class that handles all the ADO...
0
by: Tom P | last post by:
I'm using System.Configuration in .NET 2.0 to load in values from an externally specified config file and deserialize them into a C# class. During deserialization, I'm getting an exception thrown...
19
by: rich | last post by:
I am building an app using php and postgresql. My questionis this. How do you handle people wanting to make parallel changes to a record. Since in web apps you are doing a select, bring over a...
2
by: Daniel Lipovetsky | last post by:
I would like for an object to "report" to a container object when a new instance is created or deleted. I could have a container object that is called when a new instance is created, as below. ...
2
by: kodart | last post by:
Introduction Performance is the main concern to most server application developers. That’s why many of them anticipate using .NET platform to develop high performance server application regardless...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.