By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,968 Members | 1,801 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,968 IT Pros & Developers. It's quick & easy.

Access Connection

P: n/a
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\sk ipassdirect_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!
Nov 18 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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

"Simon Harris" <to*********@makesyoufat.com> wrote in message
news:eN**************@tk2msftngp13.phx.gbl...
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\sk ipassdirect_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!

Nov 18 '05 #2

P: n/a

"Mark Fitzpatrick" <ma******@fitzme.com> wrote in message
news:ua**************@TK2MSFTNGP12.phx.gbl...
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

"Simon Harris" <to*********@makesyoufat.com> wrote in message
news:eN**************@tk2msftngp13.phx.gbl...
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\sk ipassdirect_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!



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.
Nov 18 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.