Access Connection

S

Simon Harris

Hi All,

I have pieced together this from a couple of samples:

<%@ Control Language="vb" %>
<Script runat="Server">
Public Function GetConnection()
Import System.Data.OleDb
Dim Conn as OleDbConnection
Dim ConnStr as String
ConnStr="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and
Settings\Simon\My
Documents\Adotek\Projects\SkiPassDirect\private\skipassdirect_mainDB.mdb"
'For password protected DB's add "Userid=xxxx;Password=xxxxx" to the above
string
Conn=new OleDbConnection(ConnStr)
end Function
</Script>

This is in "database_connection.ascx"

I am registering the class like this:
<%@ Register TagPrefix="SPD" TagName="DBConnection"
src="/assets/classes/database_connection.ascx"%>

And opening the connection like this:
<SPD:DBConnection id="DBConnection" runat="Server"/>

I get the following error:
Compiler Error Message: BC30451: Name 'Import' is not declared.
Source Error:
Line 2: <Script runat="Server">
Line 3: Public Function GetConnection()
Line 4: Import System.Data.OleDb
Line 5: Dim Conn as OleDbConnection
Line 6: Dim ConnStr as String

Can anyone advise where I've gone wrong?

Thanks!!

Simon.


--
-
* Please reply to group for the benefit of all
* Found the answer to your own question? Post it!
* Get a useful reply to one of your posts?...post an answer to another one
* Search first, post later : http://www.google.co.uk/groups
* Want my email address? Ask me in a post...Cos2MuchSpamMakesUFat!
 
M

Mark Fitzpatrick

The Import System.Data.OleDb is in the wrong place. It must always be
outside the actual class or functions. You've got it as part of a function.
Instead, move it to it's own statement one line below the Control derective.

Hope this helsp,
Mark Fitzpatrick
Microsoft MVP - FrontPage
 
S

Simon Harris

Mark Fitzpatrick said:
The Import System.Data.OleDb is in the wrong place. It must always be
outside the actual class or functions. You've got it as part of a function.
Instead, move it to it's own statement one line below the Control derective.

Hope this helsp,
Mark Fitzpatrick
Microsoft MVP - FrontPage

Thanks Mark! Works a treat now.

Perhaps you could answer a further question, now I have my database
connection open, do I need to explicitly close it? If so, could you advise
how?

Thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,074
Latest member
StanleyFra

Latest Threads

Top