Thursday, 19 February 2009

Chart Control Problem

I've been banging my head againsta problem with the new Microsoft Charting control for an hour or so.

It turns out that the problem is simply that it can not be invisible!

I originally had the control in a Multiview and the View it was on was not the first view shown, you had to click a button or two and then the chart should appear by setting its view to be the active one. No luck, when it came time to display the view the "Error executing child request for ChartImg.axd" error came up.

So thinking it might be linked to the Multiview, I simply turned the chart invisible. Same problem.

But if I leave the chart on the screen at all time and simply use a style sheet to hide and show it, it works fine. So it seems that the problem is just that if the chart is first invisible ( server-side ) it will crash when you make it visible.

A bit crap really, but never mind, it's done now, phew!

Wednesday, 18 February 2009

C# Extention methods

This is a way of extending a class by adding methods to it. Heres a sample extention method class.

namespace ExtentionMethodSample
public static class ExtentionMethodSampleClass
public static Int32 myToInt32(this string s)
return Convert.ToInt32(s);

This example method adds a new method called "myToInt32" to the standard "string" class. This method will appear in intellisense.

In this case it simply allows you to convert a string to an Int32, which is a bit daft, but it could do any number of things. For instance it might return -1 if the string is empty. You can put any code into the method.

Another example is you might extend the DataRow class to return a Company object, as an alternative to creating a class that requires a DataRow in its constructor.

Another sample I've seen is where "string" was extended to give it a method to return only the numeric parts of the strings contents.

Tuesday, 17 February 2009

Returning tables from TSQL Functions

I was just blown away when I saw that you could return a table from a TSQL function. It's just something I've not seen before despite working with TSQL for years.

Heres a sample function :

RETURNS @MyTbl TABLE(ID INT NOT NULL, Keyword varchar(max))
INSERT INTO @myTbl (ID,Keyword)
SELECT CompanyID, CompanyName FROM Company

...and calling it ...

select * from dbo.FNHTest()

... I wonder if this is how Views are created and used internally by SQL?