Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old December 7th, 2010, 03:47 AM
Registered User
 
Join Date: Nov 2010
Location: Noardburgum, Friesland, The Netherlands
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:
Code:
try
{
 ds = newDataSet(); // Instantiate DataSet object
 conn.Open();
 command.CommandText = txtQuery.Text;
 adapter = newOleDbDataAdapter(command);
 adapter.Fill(ds);
 dataGridView1.DataSource = ds.Tables[0];
 command.ExecuteNonQuery();
}
catch (Exception ex)
{
 MessageBox.Show("Error: " + ex.Message);
}
finally
{
 conn.Close();
}
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.
  #2 (permalink)  
Old December 8th, 2010, 12:36 AM
Friend of Wrox
Points: 1,166, Level: 13
Points: 1,166, Level: 13 Points: 1,166, Level: 13 Points: 1,166, Level: 13
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Sep 2008
Location: Indianapolis, IN, USA.
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)
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 03:54 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.