473,653 Members | 3,000 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

A question about accessing a database using ado.net

Hello!

This method below works but how can it work when I don't have any open on
myOleDbConnecti on ?
As I have understood this is that there must exist an myOleDbConnecti on
..Open(); in my case
but it works just as good with one as without one.
public ArrayList GetAllPostNames ()
{
// here I get the connection from a singleton in a class library dll
OleDbConnection myOleDbConnecti on =
MeltPracStorage .instance.utcas MspDbConnection ;
DataSet dataSet = new DataSet();
ArrayList arrayList = new ArrayList();

OleDbDataAdapte r myOleDbAdapter = new OleDbDataAdapte r("select * "
+
"from MSP_COMP t1 " +
"where ACTIVE = 1 and " +
"SAVE_TIME = " +
"(select max(SAVE_TIME) " +
"from MSP_COMP " +
"where COMP_NAME = t1.COMP_NAME)
order by COMP_NAME", myOleDbConnecti on);

myOleDbAdapter. Fill( dataSet );

//loop through the dataset and add each COMP_NAME result to the
ArrayList and return it
foreach( DataRow row in dataSet.Tables[0].Rows)
arrayList.Add( row["COMP_NAME"] );

return arrayList;
}

//Tony
Aug 18 '06 #1
3 1769
Hi Tony,

DataAdapter.Fil l works in two ways.

1) If there is an open connection, this connection is used, and the connection is left untouched
2) If no connection is found. Connection.Open is called, and Connection.Clos e is called after Fill

On Fri, 18 Aug 2006 13:32:22 +0200, tony <jo************ *****@telia.com >wrote:
Hello!

This method below works but how can it work when I don't have any openon
myOleDbConnecti on ?
As I have understood this is that there must exist an myOleDbConnecti on
.Open(); in my case
but it works just as good with one as without one.
public ArrayList GetAllPostNames ()
{
// here I get the connection from a singleton in a class library dll
OleDbConnection myOleDbConnecti on =
MeltPracStorage .instance.utcas MspDbConnection ;
DataSet dataSet = new DataSet();
ArrayList arrayList = new ArrayList();

OleDbDataAdapte r myOleDbAdapter = new OleDbDataAdapte r("select * "
+
"from MSP_COMP t1 " +
"where ACTIVE = 1 and " +
"SAVE_TIME = " +
"(select max(SAVE_TIME) " +
"from MSP_COMP " +
"where COMP_NAME = t1.COMP_NAME)
order by COMP_NAME", myOleDbConnecti on);

myOleDbAdapter. Fill( dataSet );

//loop through the dataset and add each COMP_NAME result to the
ArrayList and return it
foreach( DataRow row in dataSet.Tables[0].Rows)
arrayList.Add( row["COMP_NAME"] );

return arrayList;
}

//Tony


--
Happy coding!
Morten Wennevik [C# MVP]
Aug 18 '06 #2
Hello!!

Do you recomment that a close should be used in my case or can I just leave
it as my method below is now.

//Tony
"Morten Wennevik" <Mo************ @hotmail.comskr ev i meddelandet
news:op.teg89bx aklbvpo@stone.. .
Hi Tony,

DataAdapter.Fil l works in two ways.

1) If there is an open connection, this connection is used, and the
connection is left untouched
2) If no connection is found. Connection.Open is called, and
Connection.Clos e is called after Fill

On Fri, 18 Aug 2006 13:32:22 +0200, tony <jo************ *****@telia.com >
wrote:
Hello!

This method below works but how can it work when I don't have any open on
myOleDbConnecti on ?
As I have understood this is that there must exist an myOleDbConnecti on
.Open(); in my case
but it works just as good with one as without one.
public ArrayList GetAllPostNames ()
{
// here I get the connection from a singleton in a class library
dll
OleDbConnection myOleDbConnecti on =
MeltPracStorage .instance.utcas MspDbConnection ;
DataSet dataSet = new DataSet();
ArrayList arrayList = new ArrayList();

OleDbDataAdapte r myOleDbAdapter = new OleDbDataAdapte r("select *
"
+
"from MSP_COMP t1 " +
"where ACTIVE = 1 and " +
"SAVE_TIME = " +
"(select max(SAVE_TIME) " +
"from MSP_COMP " +
"where COMP_NAME =
t1.COMP_NAME)
order by COMP_NAME", myOleDbConnecti on);

myOleDbAdapter. Fill( dataSet );

//loop through the dataset and add each COMP_NAME result to the
ArrayList and return it
foreach( DataRow row in dataSet.Tables[0].Rows)
arrayList.Add( row["COMP_NAME"] );

return arrayList;
}

//Tony


--
Happy coding!
Morten Wennevik [C# MVP]
Aug 18 '06 #3
You can leave it as it is

On Fri, 18 Aug 2006 13:57:11 +0200, tony <jo************ *****@telia.com >wrote:
Hello!!

Do you recomment that a close should be used in my case or can I just leave
it as my method below is now.

//Tony
"Morten Wennevik" <Mo************ @hotmail.comskr ev i meddelandet
news:op.teg89bx aklbvpo@stone.. .
Hi Tony,

DataAdapter.Fil l works in two ways.

1) If there is an open connection, this connection is used, and the
connection is left untouched
2) If no connection is found. Connection.Open is called, and
Connection.Clos e is called after Fill

On Fri, 18 Aug 2006 13:32:22 +0200, tony <jo************ *****@telia.com >
wrote:
>Hello!

This method below works but how can it work when I don't have any open on
myOleDbConnect ion ?
As I have understood this is that there must exist an myOleDbConnecti on
.Open(); in my case
but it works just as good with one as without one.
public ArrayList GetAllPostNames ()
{
// here I get the connection from a singleton in a class library
dll
> OleDbConnection myOleDbConnecti on =
MeltPracStorag e.instance.utca sMspDbConnectio n;
DataSet dataSet = new DataSet();
ArrayList arrayList = new ArrayList();

OleDbDataAdapte r myOleDbAdapter = new OleDbDataAdapte r("select *
"
>+
"from MSP_COMP t1 " +
"where ACTIVE = 1 and " +
"SAVE_TIME = " +
"(select max(SAVE_TIME) " +
"from MSP_COMP " +
"where COMP_NAME =
t1.COMP_NAME)
>order by COMP_NAME", myOleDbConnecti on);

myOleDbAdapter. Fill( dataSet );

//loop through the dataset and add each COMP_NAME result to the
ArrayList and return it
foreach( DataRow row in dataSet.Tables[0].Rows)
arrayList.Add( row["COMP_NAME"] );

return arrayList;
}

//Tony

--
Happy coding!
Morten Wennevik [C# MVP]


--
Happy coding!
Morten Wennevik [C# MVP]
Aug 18 '06 #4

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

Similar topics

1
1659
by: Dwayne Epps | last post by:
I'm somewhat new to developing in ASP. I've some some fairly basic stuff with it. I've just created a simple form that writes information to an Access database using ASP. Everything works fine. My question is, would there be any reason to use the session object other than for tracking purposes. Specifically, does a session have any inportance on multiple users accessing pages and submitting the form inforamtion to the database. I was...
125
14702
by: Sarah Tanembaum | last post by:
Beside its an opensource and supported by community, what's the fundamental differences between PostgreSQL and those high-price commercial database (and some are bloated such as Oracle) from software giant such as Microsoft SQL Server, Oracle, and Sybase? Is PostgreSQL reliable enough to be used for high-end commercial application? Thanks
0
1675
by: DB2usa | last post by:
Hi, Here is a non-profit website about DB2 for z/OS and OS/390 (IBM mainframes): http://www.db2usa.r8.org or http://db2usa2.free.fr/eliendb2.htm Last update on Tuesday, June 1st 2004
3
4312
by: prodirect | last post by:
Hi all, I hope someone can help me. I've recently created a database and wanted to put it up on an ftp sight so that multiple people could access the same tables at the same time from different geographical locations. I have been completely unsucessful in acheiving this goal so far however. Things I have tried: Create a shortcut to ftp sight via browser then tried to map local drive to
2
1809
by: DanB | last post by:
I am using VB DotNet Std Edition and am writing a web application that needs to read and write to an password protected database. The mdb files reside in a folder (fpdb) under the localhost (c:\inetpub\wwroot) Within the IDE I can view the data using the server explorer and I use that same oledb connection for the web form. I have tried accessing a non-password protected db in the same folder using
14
2399
by: johnsobd | last post by:
I am accessing an existing Foxpro database, of which I have no control over. I have been successful in accessing all the tables except for one. This one table I can access the first 9 fields in the table, but VB.NET will not see any fields past the first nine. I have discovered that the problem is the 10th field name begins with a 1. I was able to create a copy of this table, rename the field and can successfully access it. The...
3
13789
by: =?Utf-8?B?RGFuZGFuIFpoYW5n?= | last post by:
Now I have a web application, a web service and a SQL Server database. The Web application will invoke the web service, the web service invokes the SQL Server stored procedure. I let the web service run in an application pool which runs under a domain user, this domain user has permissions of accessing database and the connection to database is trusted connection. All these work well. The web application will be used in internet (not...
3
5630
by: Nathan Sokalski | last post by:
When I attempt to access a Microsoft Access database from my website, I recieve the following error: Server Error in '/' Application. -------------------------------------------------------------------------------- Security Exception Description: The application attempted to perform an operation not allowed by the security policy. To grant this application the required permission please contact your system administrator or change the...
4
2757
by: scout3014 | last post by:
Hi I am using WAMP5 to create web applications. I have a problem as far as accessing the database is concerned. This following code is used to access database: $con = mysql_connect("localhost", "root", ""); if (!con) { die('Could not Connect' . mysql_error()); }
5
1543
by: JT | last post by:
Hi, I would like opinions on a shareware issue. If shareware uses an online database to hold registration codes, which get copied locally and therefore only needs to check online if the shareware is not yet registered or if the registration code was lost, should there be an "Is it okay to go get your lost registration code?" message box? I've been told that certain firewalls will disallow everything until you've allowed it. I imagine...
0
8370
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8283
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8811
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8470
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8590
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7302
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5620
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
2707
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 we have to send another system
1
1914
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.