473,498 Members | 1,704 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

asp.net Technique Question

Hi there
Lets say that I put up a form which asks to create a user id and password. I place a button on the form and in the onclick I call two separate subroutines, The first checks to see if the userid already exists, the second will create the user Id. I'm going to need to connect to the database for both operations, my question is, can I create a connection object good for both operations. I guess the real question is the scope of the connection object I create. Can I define the connection object on the form level as I would in VB6 so that the connection object is available in both subroutines? Does asp.net have anything like a VB6 module where all forms can access the same code. Thanks in advance.
Nov 18 '05 #1
5 1070
you can define it

Dim ConnectionString As String =
"server=(local);database=pubs;trusted_connection=t rue"

Dim SelectCommand As String = "SELECT * from Authors"

then call it anywhere in the ASP.NET page

"Charlie Dison" <ch****************@vitalworks.com> wrote in message
news:1F**********************************@microsof t.com...
Hi there,
Lets say that I put up a form which asks to create a user id and

password. I place a button on the form and in the onclick I call two
separate subroutines, The first checks to see if the userid already exists,
the second will create the user Id. I'm going to need to connect to the
database for both operations, my question is, can I create a connection
object good for both operations. I guess the real question is the scope of
the connection object I create. Can I define the connection object on the
form level as I would in VB6 so that the connection object is available in
both subroutines? Does asp.net have anything like a VB6 module where all
forms can access the same code. Thanks in advance.
Nov 18 '05 #2
you may use global.ascx for all the pages
"Charlie Dison" <ch****************@vitalworks.com> wrote in message
news:1F**********************************@microsof t.com...
Hi there,
Lets say that I put up a form which asks to create a user id and

password. I place a button on the form and in the onclick I call two
separate subroutines, The first checks to see if the userid already exists,
the second will create the user Id. I'm going to need to connect to the
database for both operations, my question is, can I create a connection
object good for both operations. I guess the real question is the scope of
the connection object I create. Can I define the connection object on the
form level as I would in VB6 so that the connection object is available in
both subroutines? Does asp.net have anything like a VB6 module where all
forms can access the same code. Thanks in advance.
Nov 18 '05 #3
You can keep the connection on the form level. Just declare the connection
variable at the top and use it in both the subroutines. Connect to the
database in the first subroutine and don't close it. Use the same connection
from your second subroutine and close it in that sub.
But why do you need to call two subroutines? Why don't you do both the
checking and the adding in the db in the OnClick?

Hope this helps


"Charlie Dison" <ch****************@vitalworks.com> wrote in message
news:1F**********************************@microsof t.com...
Hi there,
Lets say that I put up a form which asks to create a user id and

password. I place a button on the form and in the onclick I call two
separate subroutines, The first checks to see if the userid already exists,
the second will create the user Id. I'm going to need to connect to the
database for both operations, my question is, can I create a connection
object good for both operations. I guess the real question is the scope of
the connection object I create. Can I define the connection object on the
form level as I would in VB6 so that the connection object is available in
both subroutines? Does asp.net have anything like a VB6 module where all
forms can access the same code. Thanks in advance.
Nov 18 '05 #4
You can keep the connection on the form level. Just declare the connection
variable at the top and use it in both the subroutines. Connect to the
database in the first subroutine and don't close it. Use the same connection
from your second subroutine and close it in that sub.
But why do you need to call two subroutines? Why don't you do both the
checking and the adding in the db in the OnClick?

Hope this helps
"Charlie Dison" <ch****************@vitalworks.com> wrote in message
news:1F**********************************@microsof t.com...
Hi there,
Lets say that I put up a form which asks to create a user id and

password. I place a button on the form and in the onclick I call two
separate subroutines, The first checks to see if the userid already exists,
the second will create the user Id. I'm going to need to connect to the
database for both operations, my question is, can I create a connection
object good for both operations. I guess the real question is the scope of
the connection object I create. Can I define the connection object on the
form level as I would in VB6 so that the connection object is available in
both subroutines? Does asp.net have anything like a VB6 module where all
forms can access the same code. Thanks in advance.
Nov 18 '05 #5
Hi,

I agree with Martha on it. Although we can declare it and use it in
different subroutines, it is not recommended. In ASP.NET programming, it is
recommended to open and close DB connection as soon as possible to release
resource. The DB connection is fetched from connection pool to improve
performance.

For more details, pleaes refer to MSDN article"
".net data access architecture guide"
http://msdn.microsoft.com/library/de...us/dnbda/html/
daag.asp

This document provides guidelines for implementing an ADO.NET-based data
access layer in a multi-tier .NET-based application. It focuses on a range
of common data access tasks and scenarios, and presents guidance to help
you choose the most appropriate approaches and techniques.

Hope that helps.

Best regards,
Yanhong Huang
Microsoft Community Support

Get Secure! ¨C www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 18 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
1176
by: Samuel Hon | last post by:
Hi All I'm creating some SPs and I've got a query which is inserting data into a table with a a unique constraint: CREATE TABLE ( IDENTITY (1, 1) NOT NULL , (50) COLLATE...
0
1399
by: deathyam | last post by:
Hi, I am writing an application in Excel 97 in which the users click a button and data is saved/read to and from an Access 97 database on the LAN. I am concerned about performance because there...
7
2668
by: Charles Law | last post by:
My first thought was to call WorkerThread.Suspend but the help cautions against this (for good reason) because the caller has no control over where the thread actually stops, and it might have...
2
1458
by: Niklas Norrthon | last post by:
I want to share a technique I recently have found to be useful to get around some obstacles that data protection can raise. Consider the following class: // foo.h #ifndef H_FOO #define H_FOO...
18
2312
by: xahlee | last post by:
Last year, i've posted a tutorial and commentary about Python and Perl's sort function. (http://xahlee.org/perl-python/sort_list.html) In that article, i discussed a technique known among...
5
14672
by: TomB | last post by:
I came up with this idea to show the larger picture of a thumbnail by hiding it with css and "unhide" it when one hovers over the thumbnail. I think it looks pretty nifty, but the problem with this...
3
4875
by: pragy | last post by:
Hey, can any one help me for writing a program of naive gauss elimintaion technique? It's a technique to solve system of simultaneous linear equations using matrix. thanks
3
1177
by: JohnSmith70 | last post by:
Can anybody help me understand how to implement this technique on a sample question please? thanks
2
1639
by: Bob Alston | last post by:
Recently I have been helping a nonprofit modify a system built in Access, that they acquired from another nonprofit. I am doing this as a volunteer. I would like your perspective on two...
1
368
by: Ben Bacarisse | last post by:
cri@tiac.net (Richard Harter) writes: <snip> I too was going to mention the technique until I saw Eric's reply because in your sketch you said: | we have definitions like | | struct...
0
7125
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7002
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
6887
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7379
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
4910
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4590
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
1419
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
656
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
291
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.