473,385 Members | 1,838 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,385 software developers and data experts.

Enterprise Library and Dataset Update

Hi,

I have a relativley large/complex typed dataset that contains 7-8 tables and
some supporting relational tables (lookups) for many-to-many relations. A
good exampel would be a dataset that contained the whole Northwind database
with all tables and relations.

In my business logic I will retrive a populated instance of the dataset and
perform some operations (adding/deleting/updating of rows in various
tables...).

What is the best way to persist these changes back to the database (SQL
Server)?.

I would rely appreciate a link to a relativly complete exampel or if someone
could detail how/and what best practices is for a scenario like this one.

Regards
/Oscar
Nov 17 '05 #1
4 3785
Just use the SqlDataAdapter!

you can look for it on the msdn website msdn.microsoft.com/library en
search for the SqlDataAdapter class, there will be an example of how to
load and save data by using the DataAdapter class.

greetz

Oscar Thornell schreef:
Hi,

I have a relativley large/complex typed dataset that contains 7-8 tables and
some supporting relational tables (lookups) for many-to-many relations. A
good exampel would be a dataset that contained the whole Northwind database
with all tables and relations.

In my business logic I will retrive a populated instance of the dataset and
perform some operations (adding/deleting/updating of rows in various
tables...).

What is the best way to persist these changes back to the database (SQL
Server)?.

I would rely appreciate a link to a relativly complete exampel or if someone
could detail how/and what best practices is for a scenario like this one.

Regards
/Oscar

Nov 17 '05 #2
Ok! Thanks Dries...
The SqlDataAdapter is of course the class that ADO.NET will use to transfer
data between a Dataset and persistent storage.
The core in my question is really what is the best practices to obtain the
SqlCommand instance for the current state of my dataset...
In other words: I donīt want to write the extreme amount of sql manually
that such an update would require...

///
I donīt want 1000 rows of this with coresponding sprocs:
// Establish our Insert, Delete, and Update commands
DBCommandWrapper insertCommandWrapper =
db.GetStoredProcCommandWrapper("AddProduct");
insertCommandWrapper.AddInParameter("@CategoryID", DbType.Int32,
"CategoryID", DataRowVersion.Current);
insertCommandWrapper.AddInParameter("@UnitPrice", DbType.Currency,
"UnitPrice", DataRowVersion.Current);

DBCommandWrapper deleteCommandWrapper =
db.GetStoredProcCommandWrapper("DeleteProduct");
deleteCommandWrapper.AddInParameter("@ProductID", DbType.Int32, "ProductID",
DataRowVersion.Current);

DBCommandWrapper updateCommandWrapper =
db.GetStoredProcCommandWrapper("UpdateProduct");
updateCommandWrapper.AddInParameter("@ProductID", DbType.Int32, "ProductID",
DataRowVersion.Current);
updateCommandWrapper.AddInParameter("@LastUpdate", DbType.DateTime,
"LastUpdate", DataRowVersion.Current);
///

So basically should I use the SqlCommandBuilder class here? Or what? What
support(or rather recommendations..) is there for Entlib here?
Maybee I am just stupid here..but I would rely like some advice.. ->
pointers to best practices code here...

/Oscar

"Dries De Rudder" <dr***@bestopia.be> wrote in message
news:11***************@seven.kulnet.kuleuven.ac.be ...
Just use the SqlDataAdapter!

you can look for it on the msdn website msdn.microsoft.com/library en
search for the SqlDataAdapter class, there will be an example of how to
load and save data by using the DataAdapter class.

greetz

Oscar Thornell schreef:
Hi,

I have a relativley large/complex typed dataset that contains 7-8 tables
and some supporting relational tables (lookups) for many-to-many
relations. A good exampel would be a dataset that contained the whole
Northwind database with all tables and relations.

In my business logic I will retrive a populated instance of the dataset
and perform some operations (adding/deleting/updating of rows in various
tables...).

What is the best way to persist these changes back to the database (SQL
Server)?.

I would rely appreciate a link to a relativly complete exampel or if
someone could detail how/and what best practices is for a scenario like
this one.

Regards
/Oscar

Nov 17 '05 #3
Oscar,

there is a way to simplify your problem the SqlCommandBuilder. This
class creates the InsertCommand, UpdateCommand and DeleteCommand for
you, based on the SelectCommand.

an example the way this works:

SqlConnection conn = new SqlConnection(...);
SqlCommand selectcmd = new SqlCommand("SELECT * FROM tablename",conn);

SqlDataAdapter da = new SqlDataAdapter(selectcmd);
SqlCommandBuilder cb = new SqlCommandBuilder(da);

and here everything is ready to be used.

the SqlCommandBuilder needs the SqlDataAdapter as a
constructor-parameter, it will use the SelectCommand property of the
SqlDataAdapter en create the three other Commands for you, and add them
to the SqlDataAdapter.

Be careful: Microsoft does advice to use the CommandBuilder only once,
just to create the sql-strings etc. For performance reasons you have to
retype the Insert, Update and Delete commands afterwards yourself.

so Oscar, I hope this is a more complete answer.

succes, Dries

Oscar Thornell schreef:
Ok! Thanks Dries...
The SqlDataAdapter is of course the class that ADO.NET will use to transfer
data between a Dataset and persistent storage.
The core in my question is really what is the best practices to obtain the
SqlCommand instance for the current state of my dataset...
In other words: I donīt want to write the extreme amount of sql manually
that such an update would require...

///
I donīt want 1000 rows of this with coresponding sprocs:
// Establish our Insert, Delete, and Update commands
DBCommandWrapper insertCommandWrapper =
db.GetStoredProcCommandWrapper("AddProduct");
insertCommandWrapper.AddInParameter("@CategoryID", DbType.Int32,
"CategoryID", DataRowVersion.Current);
insertCommandWrapper.AddInParameter("@UnitPrice", DbType.Currency,
"UnitPrice", DataRowVersion.Current);

DBCommandWrapper deleteCommandWrapper =
db.GetStoredProcCommandWrapper("DeleteProduct");
deleteCommandWrapper.AddInParameter("@ProductID", DbType.Int32, "ProductID",
DataRowVersion.Current);

DBCommandWrapper updateCommandWrapper =
db.GetStoredProcCommandWrapper("UpdateProduct");
updateCommandWrapper.AddInParameter("@ProductID", DbType.Int32, "ProductID",
DataRowVersion.Current);
updateCommandWrapper.AddInParameter("@LastUpdate", DbType.DateTime,
"LastUpdate", DataRowVersion.Current);
///

So basically should I use the SqlCommandBuilder class here? Or what? What
support(or rather recommendations..) is there for Entlib here?
Maybee I am just stupid here..but I would rely like some advice.. ->
pointers to best practices code here...

/Oscar

"Dries De Rudder" <dr***@bestopia.be> wrote in message
news:11***************@seven.kulnet.kuleuven.ac.be ...
Just use the SqlDataAdapter!

you can look for it on the msdn website msdn.microsoft.com/library en
search for the SqlDataAdapter class, there will be an example of how to
load and save data by using the DataAdapter class.

greetz

Oscar Thornell schreef:
Hi,

I have a relativley large/complex typed dataset that contains 7-8 tables
and some supporting relational tables (lookups) for many-to-many
relations. A good exampel would be a dataset that contained the whole
Northwind database with all tables and relations.

In my business logic I will retrive a populated instance of the dataset
and perform some operations (adding/deleting/updating of rows in various
tables...).

What is the best way to persist these changes back to the database (SQL
Server)?.

I would rely appreciate a link to a relativly complete exampel or if
someone could detail how/and what best practices is for a scenario like
this one.

Regards
/Oscar


Nov 17 '05 #4
Thanks Dries!

Some of the issues with SqlCommandBuilder like the extra roundtrip for
gathering metadata I can avoid by using a typed dataset. And for the sql
with all the WHERE clauses in this case I can live with it...

The thing that rely bothers me though is the approach taken for the actual
update...

adapter.Update(Table1);
adapter.Update(Table2);
adapter.Update(Table3);
....

I realise that this is the approach choosen by MS but I donīt like it (or
maybee understand the beauty of it..).
I would like to be able to just do one larger:

adapter.Update(myDataSet);

Somehow I hoped that I could come up with schema for this... :-(

/Oscar

"Dries De Rudder" <dr***@bestopia.be> wrote in message
news:11***************@seven.kulnet.kuleuven.ac.be ...
Oscar,

there is a way to simplify your problem the SqlCommandBuilder. This class
creates the InsertCommand, UpdateCommand and DeleteCommand for you, based
on the SelectCommand.

an example the way this works:

SqlConnection conn = new SqlConnection(...);
SqlCommand selectcmd = new SqlCommand("SELECT * FROM tablename",conn);

SqlDataAdapter da = new SqlDataAdapter(selectcmd);
SqlCommandBuilder cb = new SqlCommandBuilder(da);

and here everything is ready to be used.

the SqlCommandBuilder needs the SqlDataAdapter as a constructor-parameter,
it will use the SelectCommand property of the SqlDataAdapter en create the
three other Commands for you, and add them to the SqlDataAdapter.

Be careful: Microsoft does advice to use the CommandBuilder only once,
just to create the sql-strings etc. For performance reasons you have to
retype the Insert, Update and Delete commands afterwards yourself.

so Oscar, I hope this is a more complete answer.

succes, Dries

Oscar Thornell schreef:
Ok! Thanks Dries...
The SqlDataAdapter is of course the class that ADO.NET will use to
transfer data between a Dataset and persistent storage.
The core in my question is really what is the best practices to obtain
the SqlCommand instance for the current state of my dataset...
In other words: I donīt want to write the extreme amount of sql manually
that such an update would require...

///
I donīt want 1000 rows of this with coresponding sprocs:
// Establish our Insert, Delete, and Update commands
DBCommandWrapper insertCommandWrapper =
db.GetStoredProcCommandWrapper("AddProduct");
insertCommandWrapper.AddInParameter("@CategoryID", DbType.Int32,
"CategoryID", DataRowVersion.Current);
insertCommandWrapper.AddInParameter("@UnitPrice", DbType.Currency,
"UnitPrice", DataRowVersion.Current);

DBCommandWrapper deleteCommandWrapper =
db.GetStoredProcCommandWrapper("DeleteProduct");
deleteCommandWrapper.AddInParameter("@ProductID", DbType.Int32,
"ProductID", DataRowVersion.Current);

DBCommandWrapper updateCommandWrapper =
db.GetStoredProcCommandWrapper("UpdateProduct");
updateCommandWrapper.AddInParameter("@ProductID", DbType.Int32,
"ProductID", DataRowVersion.Current);
updateCommandWrapper.AddInParameter("@LastUpdate", DbType.DateTime,
"LastUpdate", DataRowVersion.Current);
///

So basically should I use the SqlCommandBuilder class here? Or what? What
support(or rather recommendations..) is there for Entlib here?
Maybee I am just stupid here..but I would rely like some advice.. ->
pointers to best practices code here...

/Oscar

"Dries De Rudder" <dr***@bestopia.be> wrote in message
news:11***************@seven.kulnet.kuleuven.ac.be ...
Just use the SqlDataAdapter!

you can look for it on the msdn website msdn.microsoft.com/library en
search for the SqlDataAdapter class, there will be an example of how to
load and save data by using the DataAdapter class.

greetz

Oscar Thornell schreef:

Hi,

I have a relativley large/complex typed dataset that contains 7-8 tables
and some supporting relational tables (lookups) for many-to-many
relations. A good exampel would be a dataset that contained the whole
Northwind database with all tables and relations.

In my business logic I will retrive a populated instance of the dataset
and perform some operations (adding/deleting/updating of rows in various
tables...).

What is the best way to persist these changes back to the database (SQL
Server)?.

I would rely appreciate a link to a relativly complete exampel or if
someone could detail how/and what best practices is for a scenario like
this one.

Regards
/Oscar



Nov 17 '05 #5

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

Similar topics

0
by: Mythran | last post by:
I downloaded the patterns and practices enterprise library and found that it is much different for the Data library that I am used to (SqlHelper)..It's not just an update but a total rewrite. ...
2
by: David | last post by:
I have been developing applications with Java for quite a while but I am new to .NET development. I am trying to learn the ".NET way" of creating Strongly Typed Objects from a database. The...
8
by: poifull | last post by:
Is anyone using the Microsoft Enterprise Library? If yes, do you like it or not? Any feedback will be appreciated.
0
by: Mateusz [PEYN] Adamus | last post by:
Hi I have a Typed DataSet. I've databinded it to some text controls on my form, controls show data when I show record. But now I would like to create a new record with this form, controls...
7
by: Joe | last post by:
Hello All: I am trying to use the Enterprise Libraries created by Microsoft to update a DB2 database and am stuck. I need to be able to Insert, Update and Delete records from the DB2 datbase...
0
by: TattedProgrammer | last post by:
Hello All, I am completely stuck, I have tried for an entire day to get a simple procedure call to my Oracle Db via the enterprise Library 06. I am not an oracle fan to start, but have to deal...
4
by: -pb- | last post by:
I am using .NET 2.0 along with Data Access Application Block of Enterprise Library 2.0 in one of my wrapper class and what I observered is once the connection is left open after execution of...
0
by: nostradumbass77 | last post by:
Using Enterprise Library 2.0 (Jan 06) and .NET 2.0 (VB.Net 2005) Dim dbPF As Data.Common.DbProviderFactory Try dbPF = Data.Common.DbProviderFactories.GetFactory("System.Data.OleDb") db = New...
0
by: Dharmen Patel | last post by:
I am using Enterprise Library 2006 , Data Access Application Blocks. 1. I am connecting to Oracle 9i database using DAAB. 2. I retrieve a dataset using the following code in VB.NET. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.