Wrox Programmer Forums
BOOK: Beginning C# 3.0 : An Introduction to Object Oriented Programming ISBN: 978-0-470-26129-3
This is the forum to discuss the Wrox book Beginning C# 3.0 : An Introduction to Object Oriented Programming by Jack Purdum; ISBN: 9780470261293
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning C# 3.0 : An Introduction to Object Oriented Programming ISBN: 978-0-470-26129-3 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 December 7th, 2010, 03:47 AM
Registered User
Join Date: Nov 2010
Posts: 7
Thanks: 3
Thanked 0 Times in 0 Posts
Default Ch 14 adapter.Fill and ExecuteNonQuery

Hi DrPurdum,

In Listing 14-9 in the book, in method DoQuery(), you have the following code:
 ds = newDataSet(); // Instantiate DataSet object
 command.CommandText = txtQuery.Text;
 adapter = newOleDbDataAdapter(command);
 dataGridView1.DataSource = ds.Tables[0];
catch (Exception ex)
 MessageBox.Show("Error: " + ex.Message);
I wonder why you use the command.ExecuteNonQuery() statement. As far as I can tell, the adapter.Fill(ds) already executes the SQL statement and fills the dataset.

In the book, you say that the call to Fill just passes the dataset and the ExecuteNonQuery executes the actual query. That is not what I see when debugging the code. Once the Fill has been executed, the DataSet contains a table with several rows in it.
Old December 8th, 2010, 12:36 AM
Friend of Wrox
Join Date: Sep 2008
Posts: 234
Thanks: 0
Thanked 32 Times in 30 Posts
Default ExecuteNonQuery()

It's been almost three years since I wrote that code, but the call to ExecuteNonQuery() is not needed for what the code does. My guess is that I had something in mind for later use in the code, but decided not to put it in and just left the call in. It's not an editor mistake, as my original code had it in there, too. Not sure what I was thinking...

The ExecuteNonQuery() is often used to perform catalog operations or to change the data in a database without using a DataSet by executing UPDATE, INSERT, or DELETE statements. For those operations, the call returns the number of rows affected by the call.

Sorry for the confusion...
Jack Purdum, Ph.D.
Author: Beginning C# 3.0: Introduction to Object Oriented Programming (and 14 other programming texts)
The Following User Says Thank You to DrPurdum For This Useful Post:
comecme (December 16th, 2010)

Similar Threads
Thread Thread Starter Forum Replies Last Post
Ch. 14 & ulysses Ome Ko BOOK: Professional PHP6 5 February 10th, 2011 01:54 PM
Ch 14 Help digink BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 3 November 3rd, 2009 03:35 PM
Fill the five record only adapter to data set bhasker_braj121 ADO.NET 0 July 16th, 2007 05:12 AM
Divide by Zero Error [this.Adapter.Fill(dataTable) miamikk ASP.NET 1.x and 2.0 Application Design 0 October 30th, 2006 04:26 PM
CH. 14 Stored Procedure mcauliff BOOK: Beginning ASP 3.0 1 October 4th, 2005 01:52 PM

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