473,394 Members | 2,002 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,394 software developers and data experts.

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
myOleDbConnection ?
As I have understood this is that there must exist an myOleDbConnection
..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 myOleDbConnection =
MeltPracStorage.instance.utcasMspDbConnection;
DataSet dataSet = new DataSet();
ArrayList arrayList = new ArrayList();

OleDbDataAdapter myOleDbAdapter = new OleDbDataAdapter("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", myOleDbConnection);

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 1764
Hi Tony,

DataAdapter.Fill 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.Close 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
myOleDbConnection ?
As I have understood this is that there must exist an myOleDbConnection
.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 myOleDbConnection =
MeltPracStorage.instance.utcasMspDbConnection;
DataSet dataSet = new DataSet();
ArrayList arrayList = new ArrayList();

OleDbDataAdapter myOleDbAdapter = new OleDbDataAdapter("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", myOleDbConnection);

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.comskrev i meddelandet
news:op.teg89bxaklbvpo@stone...
Hi Tony,

DataAdapter.Fill 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.Close 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
myOleDbConnection ?
As I have understood this is that there must exist an myOleDbConnection
.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 myOleDbConnection =
MeltPracStorage.instance.utcasMspDbConnection;
DataSet dataSet = new DataSet();
ArrayList arrayList = new ArrayList();

OleDbDataAdapter myOleDbAdapter = new OleDbDataAdapter("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", myOleDbConnection);

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.comskrev i meddelandet
news:op.teg89bxaklbvpo@stone...
Hi Tony,

DataAdapter.Fill 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.Close 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
myOleDbConnection ?
As I have understood this is that there must exist an myOleDbConnection
.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 myOleDbConnection =
MeltPracStorage.instance.utcasMspDbConnection;
DataSet dataSet = new DataSet();
ArrayList arrayList = new ArrayList();

OleDbDataAdapter myOleDbAdapter = new OleDbDataAdapter("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", myOleDbConnection);

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
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. ...
125
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...
0
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
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...
2
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...
14
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...
3
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...
3
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....
4
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 =...
5
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...

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.