Wrox Programmer Forums
|
BOOK: Beginning VB.NET 2nd Edition/Beginning VB.NET 2003
This is the forum to discuss the Wrox book Professional VB.NET 2003 by Bill Evjen, Billy Hollis, Rockford Lhotka, Tim McCarthy, Jonathan Pinnock, Rama Ramachandran, Bill Sheldon; ISBN: 9780764559921
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning VB.NET 2nd Edition/Beginning VB.NET 2003 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 20th, 2004, 04:40 PM
Registered User
 
Join Date: Sep 2004
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default objDataAdapter Differences

In the VB.NET book, chapter 16, there are two sample programs that use DataAdapters two different ways. I just need to validate my thinking since I either missed it in the book, or it is not clearly stated.

---- Code using objConnection.Open()---
Page 543 shows code that uses the objDataAdapter.SelectCommand properties such as:
objDataAdapter.SelectCommand = New SqlCommand
objDataAdapter.SelectCommand.Connection = objConnection
objDataAdapter.SelectCommand.CommandText = 'some SQL command here..."
objDataAdapter.SelectCommand.CommandType = CommandType.Text

after setting up these objDataAdapter properties the next line of code opens the connection to the database with objConnection.open()

--- Code without objConnection.Open() ---
Page 555 - 556 shows code that defines the objConnection using a and uses it as an argument in the data adapter constructor. So the data adapter is built as:
objDataAdapter as SqlDataAdapter = New SqlDataAdapter ("SQL code here...",objConnection)
then the code goes on to define the objDataSet, objDataView and objConnectionManager objects. The objConnection.Open() function is never called.

I tested the code without, and with the objConnection.Open() commands and the code works the same either way. So my thinking is that using the dataAdapter constructor that takes the objConnection string as an argument automatically deals with the Open and Close calls. I am confident my thinking is clear, BUT here is the rub. The database connection is obviously opening since the dataview is populated, but when is the database closed? - after the objDataAdapter.Fill as shown on page 556 perhaps?

Thanks in advance for your feedback.


 
Old September 20th, 2004, 08:09 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Hey,

The fill method opens and closes the connection. Any access through a DataSet, DataTable or DataView is disconnected from the database. The only connected object is the SQLDataReader.

Brian





Similar Threads
Thread Thread Starter Forum Replies Last Post
XML differences mrame XSLT 4 October 6th, 2008 07:34 AM
mozilla/IE 7 differences Adam H-W CSS Cascading Style Sheets 2 July 9th, 2007 04:16 AM
Code differences afharris_83 BOOK: Professional XNA Game Programming: For Xbox 360 and Windows ISBN: 978-0-470-12677-6 5 May 8th, 2007 10:14 AM
Xcode 2.4 differences craigontour Xcode 1 November 24th, 2006 11:08 PM
Variable Differences [email protected] ASP.NET 1.0 and 1.1 Basics 1 December 30th, 2003 12:16 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.