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

OleDb: DataSets versus ExecuteNonQuery(), ExecuteReader()

Hello,

My question is: is it better to use DataSets than the simple
ExecuteNonQuery() methods. I thought the DataSets would be a better
structured way of programming, but it seems to result in very lengthy
code with a lot of frustration during debugging.
This is my case:

I am creating a commerical website for a school ASP.NET project. The
code is written in C#.

I created a ShoppingCart using DataSets and DataGrids. This took me
multiple weeks to finish because of the many problems I encountered.

For example the CommandBuilder class does not work if your DataTable
is based on a SELECT-query with a 'join' in it. This means I had to
write my own Insert, Update and Delete commands with a LOT of
debugging...

This is what the code now looks like, ONLY the commands for the
shoppingcart:

DataTable dtShoppingCartChanges =
dsShopping.Tables["dtShoppingCart"].GetChanges();
if (dtShoppingCartChanges != null)
{
for (int i = 0; i < dtShoppingCartChanges.Rows.Count; i++)
{
OleDbCommand tempCommand = new OleDbCommand();

switch (dtShoppingCartChanges.Rows[i].RowState.ToString())
{
case "Modified":
{
// Update-command
string strUpdate = String.Format(
"Update tblShoppingCart " +
"Set Aantal = {0} " +
"Where ProdID = {1}",

dtShoppingCartChanges.Rows[i]["Aantal"].ToString(),

dtShoppingCartChanges.Rows[i]["ProdID"].ToString());
odbDataAdapterShoppingCart.UpdateCommand = new
OleDbCommand (strUpdate);
odbDataAdapterShoppingCart.UpdateCommand.Connectio n
= odbConnection;
}
break;
case "Added":
{
// Insert-command
string strInsert = String.Format(
"Insert into tblShoppingCart (UsrID, ProdID,
Aantal) " +
"Values ({0}, {1},{2})",

dtShoppingCartChanges.Rows[i]["UsrID"].ToString(),

dtShoppingCartChanges.Rows[i]["ProdID"].ToString(),

dtShoppingCartChanges.Rows[i]["Aantal"].ToString());
odbDataAdapterShoppingCart.InsertCommand = new
OleDbCommand (strInsert);
odbDataAdapterShoppingCart.InsertCommand.Connectio n
= odbConnection;
}
break;
case "Deleted":
{
// Delete-command
string strDelete = String.Format(
"Delete from tblShoppingCart " +
"Where ProdID = {0}",
dtShoppingCartChanges.Rows[i]["ProdID",
DataRowVersion.Original].ToString());
odbDataAdapterShoppingCart.DeleteCommand = new
OleDbCommand (strDelete);
odbDataAdapterShoppingCart.DeleteCommand.Connectio n
= odbConnection;
}
break;
}

try
{
odbDataAdapterShoppingCart.Update(dsShopping.Table s["dtShoppingCart"]);
}
catch (FormatException e)
//catch (DBConcurrencyException e)
{
}
}
}

The entire ShoppingCart page takes about 400 lines of code. I think
this is too much for a simple application. What do you think ?

Greetings,
Francis
Nov 16 '05 #1
1 5800
Hi,

"Francis" <fr*************@hotmail.com> wrote in message
news:71**************************@posting.google.c om...
Hello,

My question is: is it better to use DataSets than the simple
ExecuteNonQuery() methods. I thought the DataSets would be a better
structured way of programming, but it seems to result in very lengthy
code with a lot of frustration during debugging.
Though a code might be lengthy (hura for flexibility) many things can be
automated (code generation using wizards perhaps) or done by using higher
level methods, such as MS Data Access Application Block for .NET
http://msdn.microsoft.com/library/de...ml/daab-rm.asp.
Or you might even create such methods by yourself.
Also, I don't see any showstoper bug there - there are some but really not
vital.

The entire ShoppingCart page takes about 400 lines of code. I think
this is too much for a simple application. What do you think ?


That you are not grasping the concept of flexibility and you want one method
that does everything. ;-)

--
Miha Markic [MVP C#] - RightHand .NET consulting & software development
miha at rthand com
www.rthand.com
Nov 16 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Joe | last post by:
Hi All, I am new to using the Access DB and I need some help if someone is able to give it to me. What I want to do is get the names of the columns of certain tables. Not the data in the table...
1
by: Mark | last post by:
It appears that you can only retrieve an Output parameter from a SQL Server stored procedure when using the ExecuteNonQuery of the SqlCommand class, and cannot use the ExecuteReader() method. In...
1
by: T8 | last post by:
I have a asp.net (framework 1.1) site interfacing against SQL 2000. It runs like a charm 99% of the time but once in a while I get the following "unspecified error". Sometimes it would resolve by...
2
by: Joe | last post by:
Hello All, I am trying to insert a record in the MS Access DB and for some reason I cannot get rid of error message, System.Data.OleDb.OleDbException: Syntax error in INSERT INTO statement. ...
1
by: Joe | last post by:
Hello All, I am trying to insert a record in the MS Access DB and for some reason I cannot get rid of error message, System.Data.OleDb.OleDbException: Syntax error in INSERT INTO statement. ...
13
by: Ron L | last post by:
I am working on an application that is a front-end for a SQL database. While it is not an immediate requirement, the application will probably be required to be able to connect via the internet at...
2
by: Jason Huang | last post by:
Hi, I am not clear about the difference between the SqlCommand's ExecuteReader and ExecuteNonQuery. Would somebody show me an example to demonstrate the difference? Thanks for help. Jason
2
by: psychomad | last post by:
Please, can someone help me out to solve this error, i've been searching throughout my codes and yet i didnt succeed in finding the error!!!! The Error is: Server Error in '/' Application....
2
by: Tony Johansson | last post by:
Hello! If you do an update in the database you will use ExecuteNonQuery but the database update will work just as good if you instead use ExecuteReader or executeScalar. So my question is how...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.