Monday, January 09, 2012

Manage multiple updates to Data using C#, TSQL and OPENXML in SQL Server

I'd like to share this little technique I've been using for quite a while, especially to receive feedback and validation on whether or not this is a good idea!

I've used this technique with great success in the past in production systems which require a a "grid" of check-boxes and a single "update" button. This kind of thing usually occurs when you have any X can be related to any Y in a many to many kind of relationship. It comes in especially handy when mapping Users to Roles or that kind of thing. Though it can easily be adapted to manage multiple updates of anything in ONE database hit.

Traditionally this kind of code ends up hitting the database either once per cell in the grid or once per row in the grid because SQL Server doesn't allow arrays of things to be sent to a stored procedure. Database hits are expensive and generally less is better.

My technique leverage's SQL Servers ability to access XML data using the OPENXML keyword. When the grid of check-boxes is submitted we gather together the form collection elements (those check-boxes that have been ticked) and create an XML snippet of the results. This is then passed to SQL Server as a single input representing a set of information. OPENXML is then used inside the stored procedure to convert the XML into a temporary table which is then interrogated and used to update the relationship information that the check box represents.

Below is a link to a visual studio 2010 project that you can download , it contains all the source code for the project please feel free to download and try it for yourself - if you find it useful or have an idea of how it could be improved please leave a comment at the bottom of this page.

I have used MVC 3 and SQL Server as a simple container for the project but the technique is equally valid for any type of project Classic ASP, ASP.NET Web-forms included, so long as the RDBMS supports XML the technique will be valid.

I will refrain from a long explanation here as the code is simply one model, controller and view and the database contains just three tables and two stored procedures. If you'd like some more detail please leave a comment at the bottom of the page and Ill update as soon as possible. If I get a lot of feedback then I will flesh out the method some more in a series of posts.

I do hope you find this useful and would love to hear from you!

Project files can be downloaded here  and unpacked using   7zip

Read More

Thursday, January 05, 2012

disqus.com for @blogger @blogspot comments - really rather good!

Having not made a new years resolution at the time I have decided that it should be "use my blog more often". I'm doing quite well this year so far but to be honest its quite tricky fitting it in "out of hours" what with the twins, learning guitar and Skyrim being released but we can but try!

This post centres around the ease with which I managed to sign up for and integrate Disqus comments into this very blog. It turns out that to replace the (fairly basic) standard Blogger comments with Disqus is REALLY straightforward. Simply a case of signing up to Disqus pointing it at your blog and clicking the appropriate options.

Disqus accounts are free (though there are paid for versions) and it adds a social edge and more integrated experience if you're a Blogger or a commenter. I original was looking to integrate LiveFyre but it didn't seem to offer the kind of seamless integration and ease for which I was looking (I may be wrong but Disqus just made it so easy!).

Anyway if you're looking for "comments on social steroids) I would definitely recommend it if you're serious about building communities around your content!

http://disqus.com

http://www.livefyre.com/
One last word on LiveFyre if you're looking for something a bit different it works just like other comments managers however it also include live chat as a first-class feature which, when you see it, really is quite impressive!
Read More

Wednesday, January 04, 2012

Kodak ESP 5250 All-in-One Colour Ink-jet - Printer / copier / scanner

Having bought Kodak Camera's for both myself and my mother in law I decided to give the following printer a try when it came time to replace an older Epson model that got damaged in a house move a while ago. I have to say it is astounding for the price. B&W printing is both fast and sharp whilst the colour prints are beautiful even on normal paper! Let alone its excellent Wi-Fi facilities, combine that with its excellent cloud printing software (sadly this model does not support it natively but the software works very well indeed) its an all round winner!

Kodak also do iPhone, iPad and Andriod apps for printing directly from your smart devices for free which also "just work" - usually printers (at least for me) are a nightmare but setting all this up was a breeze!

Kodak ESP 5250 All-in-One Colour Ink-jet - Printer / copier / scanner:

'via Blog this'
Read More