Typed DataSets and Data Access Application Block ( DAAB ) - Enterprise Library Tutorials

Typed DataSets and Data Access Application Block ( DAAB ) - Enterprise Library Tutorials

by David Hayden ( Microsoft MVP C# ), Filed: Enterprise Library 3.0

 

A question that comes up often enough in the Enterprise Library Forums for me to write this tutorial is - “Can you use the Enterprise Library Data Access Application Block with Typed DataSets?” The answer is yes :)

If we take the following typed dataset:

 

Typed DataSet and Data Access Application Block

 

We can use the Enterprise Library Data Access Application Block to load a dataset and then update the changes back to the database. In this example I am using Enterprise Library 2.0. In Enterprise Library 3.0 we have the wonderful ability to use Batch Updates as mentioned here:

Here is example code for using the Typed DataSet mentioned above with the Data Access Application Block:

 

TestDataSet ds = new TestDataSet();

Database db = DatabaseFactory.CreateDatabase();

DbCommand command =
db.GetSqlStringCommand("SELECT CustomerId,
Name, EmailAddress FROM Customers
"); db.LoadDataSet(command, ds, "Customers"); foreach (TestDataSet.CustomersRow customer in ds.Customers) customer.Name += "2"; DbCommand updateCommand =
db.GetSqlStringCommand("Update Customers SET Name =
@Name, EmailAddress = @EmailAddress WHERE
CustomerId = @CustomerId
"); db.AddInParameter(updateCommand, "Name", DbType.String,
"Name", DataRowVersion.Current); db.AddInParameter(updateCommand, "EmailAddress", DbType.String,
"EmailAddress", DataRowVersion.Current); db.AddInParameter(updateCommand, "CustomerId", DbType.Int32,
"CustomerId", DataRowVersion.Current); db.UpdateDataSet(ds, "Customers", null, updateCommand,
null, UpdateBehavior.Continue);

 

Conclusion

You can use the Enterprise Library Data Access Application Block with Typed DataSets.

News Feed: David Hayden ( Microsoft MVP C# )

Filed: Enterprise Library 3.0

 

posted on Thursday, February 01, 2007 8:58 PM

My Links

Post Categories

Article Categories

Archives

Loose-Leaf Tea