Click here to Skip to main content
Click here to Skip to main content
Go to top

How to automate work when working with a Typed Dataset against a database (CSC)

, 22 Nov 2006
Rate this:
Please Sign up or sign in to vote.
DatasetAdaptor encapsulates a dataset and permits automating the work between the database and the dataset.

Sample Image - DatasetAdaptor.jpg

Introduction

Have you always wanted to be able to update a dataset in a batch, or fill its contents from a database with just one command? I have... in a project 10 months ago, I thought about it, but I had then never heard about Reflection.

After reading, profiling, factoring and refactoring.. reading again... I'm beginning to understand that Reflection allow us to do every thing...

With this tool, you will be able to fill or update a whole dataset with two lines of code...

I decided to write this when making searching for a tool which could enable something like this... I discovered the mocosh tool which seemed really useful. I didn't test it, but I understood from the screenshot that generated classes should be quite easy to combine...

Warning

This tool is a tracking tool for ASP.NET. I wanted to do batch updates every hour on the database to minimize calls to it. It doesn't assume any transactions (currently).

Also, as I wrote this for my project, I made every test specifically for my database schema.

Content

  1. DataSetAdaptor
  2. Encapsulates a dataset and permits automating the work between the database and the dataset.

  3. HlpReflexion
  4. Contains some useful methods to work with Reflection.

How to use it

  1. Create your database.
  2. Create your DataSet in Design mode by drag & dropping a table on this to ensure the creation of table adaptors. In fact, you have to do this to ensure the naming conventions of TableAdapters generated by CSC are followed. If you want to work in a different way... I propose extending DataSetValidator and overriding the GetAdapter method (see the remarks in the class).
  3. Declare your DataSet in your application as usual.
  4. Add a reference of DataDigest.Datas.Helper in your project, or copy the classes in it.
  5. Instantiate the DataSetAdapter for your DataSet as you would with a TableAdapter for a DataTable.
  6. DataSetAdaptor<typedDataSet><SAMPLEDBDATASET> dtsAdaptor 
        = new DataSetAdaptor<typedDataSet>(dataSet);
  7. After this is done, you'll want to download data from the database and fill in the dataset:
  8. dtsAdaptor.Fill();
  9. Later, when you want to update the database....
  10. dtsAdaptor.Update();

Remark

I know that using generics in this case is not useful, but I think this tool has a future. It may be useful to recover the typed encapsulated dataset without casting.

Conclusion

Use this for non-critical applications. Datasets are only useful for these kinds of application in my opinion. For good maintenance, I have only one word... NHibernate.

Remark

Sorry about my poor English.

Update

  • 06-11-22: Handles exceptions at filling and saving time. Warning: there is no transactions support.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

BlaiseBraye
Other UMH
Belgium Belgium
* Bachelor of Information Management at ISAT Charleroi in Belgium.
* Master II of Information science at UMH Mons.
 
I spend my time in small projects which can help me or small enterprises and
I am very interested in designing projects
with specifications of UML or in applying usual design patterns.

Comments and Discussions

 
QuestionError handling Pinmembergeorani22-Nov-06 3:31 
AnswerRe: Error handling PinmemberBlaiseBraye22-Nov-06 5:00 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web01 | 2.8.140922.1 | Last Updated 22 Nov 2006
Article Copyright 2006 by BlaiseBraye
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid