[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 240
  • Last Modified:

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.
0
laureola
Asked:
laureola
  • 7
  • 4
1 Solution
 
allanau20Commented:
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.
0
 
laureolaAuthor Commented:
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?
0
 
allanau20Commented:
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.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
laureolaAuthor Commented:
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.
0
 
allanau20Commented:
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?

0
 
allanau20Commented:
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()

0
 
laureolaAuthor Commented:
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
0
 
allanau20Commented:
Did you get the error at this line: DatabaseFunctions .DatabaseFunctions

There shouldn't be any spaces there, my bad.

If that doesn't work try: Dim sqlCls as NEW personal_effects.DatabaseFunctions

0
 
allanau20Commented:
DatabaseFunctions .DatabaseFunctions
                          ^
                       no space
0
 
laureolaAuthor Commented:
Thanks.

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

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 7
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now