15 Minute Intro to SharePoint Branding

26 05 2009

Yaroslav has a great intro webcast to SharePoint branding and also demonstrates the FireBug add-in to FireFox.





Comprehensive list of development tools for SharePoint Server 2007

16 05 2009

A great list of development tools for SharePoint, found on CodeProject.





Sky HD Box Showing Blue Screen

16 05 2009

The Sky HD box just starts showing a blue screen today, after googling I try a forced update;

  1. Switch off the sky power
  2. Hold the back up button on top of the box and power on.
  3. Wait until 4 LED’s light up (this can take up to 30 seconds), the screen should say updating don’t switch off
  4. Wait for up to 10mins
  5. Box will go into standby give it couple of minutes and see if it comes out of standby

This didn’t work but amazingly this seemingly nonsense set of instructions does;

  1. Unplug power lead from Sky
  2. Disconnect/connect HDMI from Sky
  3. Disconnect/connect HDMI from TV
  4. Reconnect Sky power
  5. Wait a minute or two
  6. Press ‘Sky’ button on remote

Thanks to this post for the tips.





SqlDataReader, DataTable and Multiple Resultsets

14 05 2009

Using a SqlDataReader for accessing a resultset returned from a DB is common practice, however, sometimes it’s convenient or neccesary however to use a DataTable/DataSet.

When faced with this, I commmonly load a Datatable from a DataReader, like so

var dt = new DataTable();
 

// I've got my sqldatareader from somewhere, now I'll use it to load the DataTable

dt.Load(dr);

This all works quite nicely. Now, I recently discovered that when working with multiple resultsets returned from the DB, the DataTable.Load method does something, well sneaky IMHO.

Ok, given a SQL command that returns multiple resultsets, you can access them using the SqlDataReader, as normal, except that once the .Read() method returns false, you can call the .NextResult() method to advance the SqlDataReader onto the next resultset, and continue calling .Read() untill it returns false etc.

If the .NextResult() method returns false, then there are no more resultsets. Now, after I called DataTable.Load() I called .NextResult() which returned false, which was wrong since I knew my SQL batch was returning multiple resultsets. Anyway, after much investigation and quick look with Reflector, I discover why it’s not working (and this is the sneaky bit) – DataTable.Load() calls the .NextResult() method on the supplied SqlDataReader for you, as you can see from the code snip below;

...
if (!reader.IsClosed && !reader.NextResult())
{
 reader.Close();
}
...

Ok, so then after calling DataTable.Load(), we just need to check the .HasRows property to see if there are any rows on the newly active resultset.





LINQ to Objects: Forced Result Set Evaluation

6 05 2009

Usually when using LINQ for querying object collections, evaluation or realisation of the result set is done in the lazy fashion i.e. when actually enumerating the query results. This obviously has its advantages, especially when you consider LINQ to SQL.

However when using LINQ to query object collections or strings it can be useful to force the evaluation of the result set. Why? well something I commonly do, is to use LINQ to process a collection for transformation purposes.

As an example, given a collection of integer ID’s you might like to transform that to a comma seperated string, ordinarilly you’d iterate over the collection like so;

var sb = new StringBuilder();
foreach(var num in numCollection)
{
	sb.AppendFormat("{0},", num);
}
var numColStr = sb.Remove(sb.Length - 1, 1);

Which is all well and good, using LINQ you can do the following;

var sb = new StringBuilder();
numCollection.Select(num => sb.AppendFormat("{0},", num)).Count();
var numColStr = sb.Remove(sb.Length - 1, 1);

Note the use of the .Count() method call at the end of the LINQ query, this causes the result set to be evaluated which in turn causes the select function delegate to be executed, which in this case adds the numbers in the collection to the StringBuilder.  Ok, so what if you need only some of the objects in the collection to be included in the result set and therefore ‘transformed’;

var sb = new StringBuilder();
numCollection.Where(num => num > 10 && num < 100).Select(num => sb.AppendFormat("{0},", num)).Count();
var numColStr = sb.Remove(sb.Length - 1, 1);

Other extension methods also force the evaluation of the result set, .ToArray() and .ToList() amonst them, however using .Count() iterates the result set and returns the count, while .ToArray() and .ToList() do the same but return an Array and List respectively.