Blog Stats
  • Posts - 170
  • Articles - 4
  • Comments - 54
  • Trackbacks - 7

 

System.Data.SQLClient.SqlDataAdapter? Yes but not easy to implement

To be honest, I never had the opportunity to use a such complex Dataset update before. Usually my code talk directly to the database, so it's quite easy to fix things.

But there, I went on such many problems to make this thing works. I am writing a Quiz builder for one of my projects Scoilnet, and god .Net wasn't nice with me at all. So much debugging.

The story is, because the tool has to be used by a 'general audience', I didn't want to talk to the database directly. Why? Because a user can decide to close the browser in a middle of a quiz creation, and then my nice little tables will be suddenly filled by orphans records.

So the idea was to work with a mix of ViewState and cached Dataset. Easy? Yes and No.

The most difficult part was at the end of the quiz building process, where the user click Save. Then the code has to insert different records from 4 tables in the right SQL database.

Then comes the painful process of debugging all the primary keys constraints. Indeed if your four tables are properly related in SQL Server, it's almost impossible to trigger from .Net a successful cascade updates of all the tables.

I finally gave up and actually it works pretty well if I insert the records table by table without the relationships built in SQL Server.

It's really sad that the data provider doesn't include a better and logical way to copy a cached dataset to the database automatically and following all the defined relationships.

Also very difficult to 'google' about the subject. Most of the time, in every example I could find, the dataset is created from the database, and then after transformation, sent back to SQL.

I couldn't find a good support to show how to deal with multiple tables.

Anyway, as part of my commitment for the community. the Quiz builder source will be available in Developers.ie in a couple of weeks (ready for improvements :-)

 

Comments have been closed on this topic.
 

 

Copyright © Paschal L