laureola
asked on
ADO and ASP
HELP !!!
I am in the process of creating a ASP.NET application and am new to this way of thinking.
The problem I have is that I usually use an Include file that contains my Database Functions.
eg. OPEN_DB() opens a connection, OPEN_RS() opens a Recordset
I then call these from all of my ASP pages
How can I replicate this is ASP.NET?
I need to be able to call these Sub Functions from all ASPX pages that I create.
I am in the process of creating a ASP.NET application and am new to this way of thinking.
The problem I have is that I usually use an Include file that contains my Database Functions.
eg. OPEN_DB() opens a connection, OPEN_RS() opens a Recordset
I then call these from all of my ASP pages
How can I replicate this is ASP.NET?
I need to be able to call these Sub Functions from all ASPX pages that I create.
You can pull all your methods / functions into a class and compile it into a dll. Then in your project you'll just need to reference it. Pretty cool. I have a class for DB functions and I use it for all my projects.
ASKER
Thanks.
I have done this already, but I am having trouble calling them as I normally would.
Here are my simplified functions:
===================
Imports System.Data.SqlClient
Public Class DatabaseFunctions
Sub OPEN_DB()
Dim CN As SqlConnection = New SqlConnection(Configuratio nSettings. AppSetting s("DEV_CN" ))
CN.Open()
End Sub
Sub OPEN_RS(ByVal adoSQL)
Dim RS As SqlCommand = New SqlCommand(adoSQL,CN)
End Sub
End Class
========
What I want to do is call the OPEN_DB when I need it and then call the OPEN_RS to open a Recordset that I will use in the old fashion way.
eg. WHILE NOT RS.EOF .....
Can you help here?
I have done this already, but I am having trouble calling them as I normally would.
Here are my simplified functions:
===================
Imports System.Data.SqlClient
Public Class DatabaseFunctions
Sub OPEN_DB()
Dim CN As SqlConnection = New SqlConnection(Configuratio
CN.Open()
End Sub
Sub OPEN_RS(ByVal adoSQL)
Dim RS As SqlCommand = New SqlCommand(adoSQL,CN)
End Sub
End Class
========
What I want to do is call the OPEN_DB when I need it and then call the OPEN_RS to open a Recordset that I will use in the old fashion way.
eg. WHILE NOT RS.EOF .....
Can you help here?
I think you can still use classic ADO, but the recommended way is to use ADO.NET. What kind of problems are you having?
Also, I wouldn't 'hard code' this: ConfigurationSettings.AppS ettings("D EV_CN")
What happens if you want to use it for another project? Best way is to pass it as a var.
HtH.
Also, I wouldn't 'hard code' this: ConfigurationSettings.AppS
What happens if you want to use it for another project? Best way is to pass it as a var.
HtH.
ASKER
I have placed this Class in the Index.aspx.vb file which is my only Code Behind page.
When I call the function it says that OPEN_DB() is not Declared.
When I call the function it says that OPEN_DB() is not Declared.
Did you do these things:
1. Compile your DatabaseFunctions class into a dll ?
2. In the project that has Index.aspx.vb, did you reference the dll ?
3. Did you declare and instantiate your class ?
Can you paste your code?
1. Compile your DatabaseFunctions class into a dll ?
2. In the project that has Index.aspx.vb, did you reference the dll ?
3. Did you declare and instantiate your class ?
Can you paste your code?
Let's say I did 1 & 2, then in index.aspx.vb in one of my private methods I can do this:
Dim sqlCls As New DatabaseFunctions .DatabaseFunctions
sqlCls.OPEN_DB()
Dim sqlCls As New DatabaseFunctions .DatabaseFunctions
sqlCls.OPEN_DB()
ASKER
OK ... I have a Class.
=======
Imports System.Data.SqlClient
Public Class DatabaseFunctions
Public CN As SqlConnection
Public RS As SqlCommand
Sub OPEN_DB()
CN = New SqlConnection(Configuratio nSettings. AppSetting s("DEV_CN" ))
CN.Open()
End Sub
Sub OPEN_RS(ByVal adoSQL)
RS = New SqlCommand(adoSQL, CN)
End Sub
End Class
========
I have one Index.aspx.vb page that all other APSX pages are called from (like the good old Include Days)
I have referenced the DatabaseFunctions page
========
Imports System.Data
Imports personal_effects.DatabaseF unctions
Public Class index
Inherits System.Web.UI.Page
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnostics.Debugg erStepThro ugh()> Private Sub InitializeComponent()
End Sub
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub
#End Region
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
End Sub
End Class
==========
Inside my ASPX page (Not Index.aspx, but one that page is loaded first, so I assuming the functions are loaded), I am trying to call the Functions
==========
Dim sqlCls As New DatabaseFunctions .DatabaseFunctions
sqlCls.OPEN_DB()
==========
But I get an error saying that "end of statement" expected
=======
Imports System.Data.SqlClient
Public Class DatabaseFunctions
Public CN As SqlConnection
Public RS As SqlCommand
Sub OPEN_DB()
CN = New SqlConnection(Configuratio
CN.Open()
End Sub
Sub OPEN_RS(ByVal adoSQL)
RS = New SqlCommand(adoSQL, CN)
End Sub
End Class
========
I have one Index.aspx.vb page that all other APSX pages are called from (like the good old Include Days)
I have referenced the DatabaseFunctions page
========
Imports System.Data
Imports personal_effects.DatabaseF
Public Class index
Inherits System.Web.UI.Page
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnostics.Debugg
End Sub
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub
#End Region
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
End Sub
End Class
==========
Inside my ASPX page (Not Index.aspx, but one that page is loaded first, so I assuming the functions are loaded), I am trying to call the Functions
==========
Dim sqlCls As New DatabaseFunctions .DatabaseFunctions
sqlCls.OPEN_DB()
==========
But I get an error saying that "end of statement" expected
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
DatabaseFunctions .DatabaseFunctions
^
no space
^
no space
ASKER
Thanks.
I have reverted to ASP, because my deadline is tomorrow.
Thanks for your help.
I have reverted to ASP, because my deadline is tomorrow.
Thanks for your help.
NP. Have a good day.