Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / August 2006

Tip: Looking for answers? Try searching our database.

A question about accessing a database using ado.net

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
tony - 18 Aug 2006 12:32 GMT
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
Morten Wennevik - 18 Aug 2006 12:37 GMT
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

> Hello!
>
[quoted text clipped - 33 lines]
>
> //Tony

Signature

Happy coding!
Morten Wennevik [C# MVP]

tony - 18 Aug 2006 12:57 GMT
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

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 <johansson.andersson@telia.com>
wrote:

> Hello!
>
[quoted text clipped - 33 lines]
>
> //Tony

--
Happy coding!
Morten Wennevik [C# MVP]
Morten Wennevik - 18 Aug 2006 13:39 GMT
You can leave it as it is

> Hello!!
>
[quoted text clipped - 59 lines]
> Happy coding!
> Morten Wennevik [C# MVP]

Signature

Happy coding!
Morten Wennevik [C# MVP]


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.