473,320 Members | 1,691 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

reusing code for repeated database use

Hi,
I am writing a application in ASP.net (using vb.net for my code behind).
I have many queries, all of which are against just 2 databases on a server.
This server can change, and the name is stored in an XML config file. I have
quite a bit of code, and would really like to reuse some of it. I think this
is the kind of thing that would warant making my own object for data access.
Does anyone have any tutorials, hints or best practices on doing this? I
have provided an example of my usage below.

Thanks,
Martin

--------------------CODE--------------------

'This is always the same
aConnectionString = "Data Source=" & ServerName & ";" _
& "Database=DB1;UID=UID1;PWD=PWD1"
conn = New System.Data.SqlClient.SqlConnection
conn.ConnectionString = aConnectionString
conn.Open()

'This changes
SQL = "some SQL Code"

'This is always the same
anSQLCommand = New System.Data.SqlClient.SqlCommand
anSQLCommand.Connection = conn
anSQLCommand.CommandText() = SQL

'This changes
R = anSQLCommand.ExecuteReader()
While R.Read
If Not (IsDBNull(R("aVariable"))) Then
aVariable = CDbl(R("aVariable"))
End If
End While

'This is always the same
conn.Close()
Jun 8 '06 #1
0 963

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

Similar topics

4
by: Shufen | last post by:
Hi, I'm a newbie that just started to learn python, html and etc. I have some questions to ask and hope that someone can help me on. I'm trying to code a python script (with HTML) to get...
1
by: Cherrish Vaidiyan | last post by:
hello, Thanx for replying to my earlier Google group query about Replication of Oracle 9i on RH9.IF the query followed is being repeated by me I am sorry for it.. I want to implement...
9
by: Alan | last post by:
Using VC++ (1998) compiler with PFE32 editor in Win2K Pro SP4. (DigitalMars CD on order. ) The program (below) instantiates a class and then deletes it. I would have thought that reusing the...
6
by: allyn44 | last post by:
Hi---I have to import some data from excel into an Access table--the code below is working ok but I would like to condense it by running a loop. The number of records can vary from 1 to 30 in each...
4
by: Old Wolf | last post by:
#include <stdio.h> #include <stdarg.h> Is this safe: void foo(const char *fmt, ...) { va_list ap; va_start(ap,fmt);
2
by: Andy Fish | last post by:
Hi, With languages like c# having namespaces, I was wondering what's the recommended practice for reusing source code. I'm not talking big stuff like log4net that's version controlled and...
4
by: Rob Meade | last post by:
Hi all, I'm in the middle of finishing a page and I've noticed that I have a chunk of code that is used in two places - its exactly the same - I guess I can rip this out - save it seperately and...
3
by: Vik | last post by:
I use the same dataadapters and datasets on a few aspx pages. Currently I create these data controls on each page. Is it possible to create these controls only once and then use them on the...
1
by: Alec MacLean | last post by:
Hi, Outline of problem: I've built a set of user controls that are used to output questions for a survey and gather the responses using simple radio buttons. I'm adding an optional textbox...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.