Link to home
Start Free TrialLog in
Avatar of laureola
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.
Avatar of Allan
Allan
Flag of United States of America image

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.
Avatar of laureola
laureola

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(ConfigurationSettings.AppSettings("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 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.AppSettings("DEV_CN")

What happens if you want to use it for another project? Best way is to pass it as a var.

HtH.
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.
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?

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()

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(ConfigurationSettings.AppSettings("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.DatabaseFunctions
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.DebuggerStepThrough()> 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
ASKER CERTIFIED SOLUTION
Avatar of Allan
Allan
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
DatabaseFunctions .DatabaseFunctions
                          ^
                       no space
Thanks.

I have reverted to ASP, because my deadline is tomorrow.
Thanks for your help.
NP. Have a good day.