# Wednesday, October 07, 2009
Interview screening and consulting
Wednesday, October 07, 2009 5:14:00 AM (GMT Daylight Time, UTC+01:00)  #    Disclaimer  |  Comments [1]  | 
# Tuesday, September 29, 2009
Using the MasterType directive to programatically access you Master Page.
Tuesday, September 29, 2009 5:34:35 AM (GMT Daylight Time, UTC+01:00)  #    Disclaimer  |  Comments [0]  | 
Just a general rave about WebSpark, and a rant about PayPal.
Tuesday, September 29, 2009 5:23:27 AM (GMT Daylight Time, UTC+01:00)  #    Disclaimer  |  Comments [0]  | 
# Friday, September 25, 2009
Placing page trace information in a file instead of on the page
Friday, September 25, 2009 6:11:05 AM (GMT Daylight Time, UTC+01:00)  #    Disclaimer  |  Comments [0]  | 
# Wednesday, September 23, 2009
Interview question -- the virtual keyword
Wednesday, September 23, 2009 5:45:06 AM (GMT Daylight Time, UTC+01:00)  #    Disclaimer  |  Comments [0]  | 
Fancy tooltips in WinForms!
Wednesday, September 23, 2009 4:58:23 AM (GMT Daylight Time, UTC+01:00)  #    Disclaimer  |  Comments [0]  | 
# Tuesday, September 22, 2009
Adding a WinForm tooltip without the control..
Tuesday, September 22, 2009 5:38:13 AM (GMT Daylight Time, UTC+01:00)  #    Disclaimer  |  Comments [0]  | 
Why so few posts recently..
Tuesday, September 22, 2009 5:15:25 AM (GMT Daylight Time, UTC+01:00)  #    Disclaimer  |  Comments [0]  | 
# Wednesday, September 16, 2009
How to enumerate all the shortcut keys in the Visual Studio IDE
Wednesday, September 16, 2009 6:22:12 AM (GMT Daylight Time, UTC+01:00)  #    Disclaimer  |  Comments [0]  | 

I am getting settled in my new project, and it only took me a week to get rights to install anything on the laptop! A lot of people would say "Wow, a billable week with no work!" but personally, the days just drag by. I'd much rather be buried in code. I did make some good use of the time though, digging into what documentation I could find and creating a new Functional Specification Document. I did finally get my rights, so tomorrow will be spent installing things and looking into code again.

I did get some reading done though, and I saw that in VS2010 C# will have optional and named parameters. I know the VB crowd (of which I come from) will chuckle a little at that, as that feature has been around forever. Until now, it's required C# developers to overload functions. Nothing Earth-shattering about this feature, other than as part of it, C# will support named parameters and default values as well as part of the implementation (the default values are part of the defiinition of the function).

All Things | C# | CSharp | General | VB.Net
Wednesday, September 16, 2009 5:36:56 AM (GMT Daylight Time, UTC+01:00)  #    Disclaimer  |  Comments [0]  | 
# Monday, September 07, 2009
Debugging trick for placing a condition on a breakpoint to assist in speeding up debugging.
Monday, September 07, 2009 11:46:14 PM (GMT Daylight Time, UTC+01:00)  #    Disclaimer  |  Comments [0]  | 
How to make the Visual Studio debugger break where the error actually occurs.
Monday, September 07, 2009 11:28:20 PM (GMT Daylight Time, UTC+01:00)  #    Disclaimer  |  Comments [0]  | 
# Saturday, September 05, 2009

As I was looking through Scott Hanselman's List of Tools for 2009, I saw a reference for Microsoft's Sketchflow (part of Microsoft Expression), which allows you to design (among other things) and work through ideas prior to coding. I am going to check it out this weekend, and maybe some of the alternate tools he recommended for his post.  I might even have to dust off my Table PC, as it seems like a good combination.

Saturday, September 05, 2009 4:55:17 PM (GMT Daylight Time, UTC+01:00)  #    Disclaimer  |  Comments [0]  | 
# Friday, September 04, 2009
Tipf of the Day: A brief discussion of the new Extension Methods in .Net 3.5
Friday, September 04, 2009 6:10:29 AM (GMT Daylight Time, UTC+01:00)  #    Disclaimer  |  Comments [0]  | 
# Thursday, September 03, 2009
Starting a new project, how to approach it?
Thursday, September 03, 2009 8:41:58 PM (GMT Daylight Time, UTC+01:00)  #    Disclaimer  |  Comments [0]  | 
# Wednesday, September 02, 2009

I can't take credit for this, as I took it from the article How To Get Table Row Counts Quickly And Painlessly on SqlServerCentral.com by Kendal Van Dyke. However, it such a good tip, I had to change it a bit, as I tend to use this a LOT.

First, I made the results a little more "printable" but reducing the table name column. Next, I made it a system proc because when I go onto client sites, I am looking at many databases. I probably don't need to create a procedure for it, but there have been many cases where I trend things, and it would be nice to have this handy. Finally, I added a parameter to allow me to change the sorting. By default, it sorts by table name. I added an optional parameter to allow me to pass in an integer (could have done it a million ways, I know, but I chose to do this solely for my preferences -- feel free to change to yours).

Usagesp_retrieveRowCounts    --- sorts by table name

            sp_retrieveRowCounts 1  ---sorts by row count, then table name

Here's the proc:


USE master
GO

IF (SELECT OBJECT_ID('sp_retrieveRowCounts','P')) IS NOT NULL
BEGIN
    DROP PROC sp_retrieveRowCounts
END
GO


CREATE PROC sp_retrieveRowCounts (@OrderByCount int = null)
AS
BEGIN

    DECLARE @OrderByParm int
    DECLARE @SQLStatement varchar(700)
    DECLARE @OrderByClause varchar(35)
    
    SELECT @OrderByParm = ISNULL(@OrderByCount,0)

    IF (@OrderByParm != 0)
        SELECT @OrderByClause = ' ddps.row_count DESC, o.NAME ASC'
    ELSE
        SELECT @OrderByClause = ' o.NAME ASC'

    SELECT @SQLStatement = 'SELECT TableName = LEFT(o.name,50), TotalRows = ddps.row_count FROM sys.indexes AS i
     INNER JOIN sys.objects AS o ON i.OBJECT_ID = o.OBJECT_ID
     INNER JOIN sys.dm_db_partition_stats AS ddps ON i.OBJECT_ID = ddps.OBJECT_ID
     AND i.index_id = ddps.index_id
    WHERE i.index_id < 2
     AND o.is_ms_shipped = 0
    ORDER BY '
+ @OrderByClause
    
    EXEC(@SQLStatement)

END

--Mark procedure as system object
EXEC sys.sp_MS_marksystemobject sp_retrieveRowCounts
GO


GRANT EXEC ON sp_retrieveRowCounts TO public
GO

 

Wednesday, September 02, 2009 6:34:10 PM (GMT Daylight Time, UTC+01:00)  #    Disclaimer  |  Comments [0]  | 
# Tuesday, September 01, 2009

I posted about sp_findsp previously and decided to revisit it. I didn't write it (see previous post for credit/link) but I did add a bit to it. First, I cleaned it up a bit to make it easier to read, and second, I made it so that it is a system proc so I could access it from any db on my server. I may end up doing some cleanup on it's output, but that's all I had time for for now. So here goes, the new version!

USE master
GO

PRINT 'Checking for the existence of this procedure'
IF (SELECT OBJECT_ID('sp_generate_inserts','P')) IS NOT NULL --means, the procedure already exists
BEGIN
PRINT 'Procedure already exists. So, dropping it'
DROP PROC sp_findsp
END
GO


CREATE PROC sp_findsp @s varchar(255)
AS
BEGIN
    DECLARE @msg varchar(255) ,@ul varchar(255)
    SELECT @s='%' + @s + '%'
    
    SELECT 'SP Name'=upper(o.name), Seq=colid ,'SP Line'=substring(text,patindex(@s,text)-5, 30)
    FROM syscomments c , sysobjects o
    WHERE o.id=c.id
    and patindex(@s,text) > 0
    ORDER BY [name]

    SELECT @msg='* Stored procedures containing string "' + @s + '=' + convert(varchar(8),@@rowcount) + ' *'

    SELECT @ul=replicate('*',datalength(@msg))
    PRINT ' '
    PRINT @ul
    PRINT @msg
    PRINT @ul
END
GO

--Mark procedure as system object
EXEC sys.sp_MS_marksystemobject sp_findsp
GO

PRINT 'Granting EXECUTE permission on sp_findsp to all users'
GRANT EXEC ON sp_findsp TO public

GO


All Things | C# | CSharp | General
Tuesday, September 01, 2009 5:20:43 AM (GMT Daylight Time, UTC+01:00)  #    Disclaimer  |  Comments [1]  | 

When I go onto a client site, I usually don't have the luxury of designing everything from scratch. There are times (like on my current engagement) if I were given the choice, I'd say scrap it, but usually it doesn't happen that way. It is what it is... been saying that a lot lately!

So one of the tools I find useful is the ability to search for particular field names in the database. This is very similar to sp_findsp I use, which I have posted in the past off the net, but I have modified it so it gets registered as a system procedure.

So here's sp_findfields. It will return a fairly printable representation of the results of all fields which match the passed in string. It's registered as a system procedure in this script, so it is accessible to all databases.

Usage:

sp_findfields '%Contact%'

This will find all fields with the string 'Item' in it. Note you need to provide the wildcard characters.

USE master
GO

IF (SELECT OBJECT_ID('sp_findfields','P')) IS NOT NULL
    BEGIN
        DROP PROCEDURE sp_findfields
    END
GO

CREATE PROCEDURE sp_findfields
(@searchText varchar(50))
AS
BEGIN
    
    SELECT SchemaName = LEFT(TABLE_SCHEMA,10),
        TableName = LEFT(TABLE_NAME, 35),
        FieldName = LEFT(COLUMN_NAME, 40),
        DataType = LEFT(DATA_TYPE, 13),
        DataSize = CHARACTER_MAXIMUM_LENGTH,
        AlloysNulls = IS_NULLABLE
    FROM INFORMATION_SCHEMA.columns
    WHERE column_name like @searchText
    ORDER BY TableName, FieldName
END
GO

--Mark procedure as system object
EXEC sys.sp_MS_marksystemobject sp_findfields
GO


GRANT EXEC ON sp_findfields TO public
GO

Tuesday, September 01, 2009 5:10:15 AM (GMT Daylight Time, UTC+01:00)  #    Disclaimer  |  Comments [0]  | 
# Monday, August 31, 2009

Since I am going back into full time consulting, I decided lugging around twenty 800 page books is a bad idea. Tonight, I pulled the trigger in a Kindle DX. A bit pricy, but the fact I can annotate my books (and export the annotations) and read native PDFs, I can see the value in the price. I only wish it allowed you to annotate PDFs, as I know I can put a LOT of things in PDF form and place on there.

So I was noticing Amazon charges for placing RSS feeds on the Kindle, and I decided to either find a service which converts RSS feeds to PDF format, or write one myself. Fortunately, I found Tabbloid, which mails your RSS feeds in PDF format at an interval you specify. Even better, it looks free. I may still write one and put some filtering capability in it, but this is a win for now.

The other gadget I have and just enjoy is my Pioneer XMp3 player. It allows me to record XM content, and place all kinds of music on the Micro SD card. It's still kind of buggy, and with the XM-Sirius merger, I don't imagine that will change, but I still enjoy it immensely.

Monday, August 31, 2009 5:26:21 AM (GMT Daylight Time, UTC+01:00)  #    Disclaimer  |  Comments [0]  | 
# Sunday, August 30, 2009

Normally, I don't have enough time to really dig into the bleeding edge technologies, but I am trying to rectify that. The question is always "When is it too early.."

For now, I have been looking at some of .Net 4.0's newer features, and one really cool thing for environments which have years of legacy software is called "Multi-targeting". Essentially, it allows you set the target environment for an application in the same IDE (but later target new versions).

As an example, let's say you are currently using ASP.Net 2.0, and you have to because of client concerns. No problem, you'll be able to set the VS IDE to target the 2.0 framework. However, when you decide to upgrade, you can just change the target framework version. The neat thing is that the IDE willl hide and show Intellisense based on the target framework as well.

Scott Guthie is writing a series on it I plan on following closely. This time, I may just have to be more bleeding edge than I have been in the past.

Sunday, August 30, 2009 4:31:31 PM (GMT Daylight Time, UTC+01:00)  #    Disclaimer  |  Comments [0]  | 
# Saturday, August 29, 2009

The following code snippets make retrieving values from DataRows safely, and properly casts them to the desired values.

 

        /// <summary>

        /// Gets the int value from data row.

        /// </summary>

        /// <param name="fieldName">Name of the field.</param>

        /// <param name="dr">The dr.</param>

        /// <returns></returns>

        public static int GetIntValueFromDataRow(string fieldName, DataRow dr)

        {

            return (dr[fieldName] == DBNull.Value ? 0 : Convert.ToInt32(dr[fieldName].ToString()));

        }

 

        /// <summary>

        /// Gets the int value from data row.

        /// </summary>

        /// <param name="fieldName">Name of the field.</param>

        /// <param name="dr">The dr.</param>

        /// <param name="defaultValue">The default value.</param>

        /// <returns></returns>

        public static int GetIntValueFromDataRow(string fieldName, DataRow dr, int defaultValue)

        {

            return (dr[fieldName] == DBNull.Value ? defaultValue : Convert.ToInt32(dr[fieldName].ToString()));

        }

 

        /// <summary>

        /// Gets the string value from data row.

        /// </summary>

        /// <param name="fieldName">Name of the field.</param>

        /// <param name="dr">The dr.</param>

        /// <returns></returns>

        public static string GetStringValueFromDataRow(string fieldName, DataRow dr)

        {

            return (dr[fieldName] == DBNull.Value ? String.Empty : dr[fieldName].ToString());

        }

 

        /// <summary>

        /// Gets the string value from data row.

        /// </summary>

        /// <param name="fieldName">Name of the field.</param>

        /// <param name="dr">The dr.</param>

        /// <param name="defaultValue">The default value.</param>

        /// <returns></returns>

        public static string GetStringValueFromDataRow(string fieldName, DataRow dr, string defaultValue)

        {

            return (dr[fieldName] == DBNull.Value ? defaultValue : dr[fieldName].ToString());

        }

 

        /// <summary>

        /// Gets the bool value from data row.

        /// </summary>

        /// <param name="fieldName">Name of the field.</param>

        /// <param name="dr">The dr.</param>

        /// <returns></returns>

        public static bool GetBoolValueFromDataRow(string fieldName, DataRow dr)

        {

            return (dr[fieldName] == DBNull.Value ? false : Convert.ToBoolean(dr[fieldName].ToString()));

        }

 

        /// <summary>

        /// Gets the decimal value from data row.

        /// </summary>

        /// <param name="fieldName">Name of the field.</param>

        /// <param name="dr">The dr.</param>

        /// <returns></returns>

        public static decimal GetDecimalValueFromDataRow(string fieldName, DataRow dr)

        {

            return (dr[fieldName] == DBNull.Value ? 0 : Convert.ToDecimal(dr[fieldName].ToString()));

        }

Saturday, August 29, 2009 7:32:59 PM (GMT Daylight Time, UTC+01:00)  #    Disclaimer  |  Comments [0]  | 
# Friday, August 28, 2009

I am a huge fan of CodeSmith. If you are not familiar with it, and you do any amount of coding at all, you owe it to yourself to check it out.

Below is some template code which loads the foreign keys of a table into a Dictionary object. It stores the name of the table and foreign key field name. As you can see, it generates a notice when it comes across a recursive relationship.

 

public Dictionary<string,string> GetForeignKeyTables()
{
    Dictionary<string,string> dic = new Dictionary<string,string>( );

 for (int idx = 0; idx < SourceTable.ForeignKeys.Count; idx ++)
 {
        string primaryTable = String.Empty;
        string primaryKey = String.Empty;

  // To get the foreign key columns
  ColumnSchema col1 = SourceTable.ForeignKeys[idx].ForeignKeyMemberColumns[0];
        primaryKey = col1.Name.Trim();

  // To get the foreign key tables
        primaryTable = SourceTable.ForeignKeys[idx].PrimaryKeyTable.ToString().Replace("dbo.",String.Empty).Trim();
        if (!dic.ContainsKey(primaryKey))
            dic.Add(primaryKey, primaryTable);
        else
            MessageBox.Show("This table may contain recursive relationships. You must set those relationships up manually.");
    }

    return dic;
}

 

Friday, August 28, 2009 10:48:39 PM (GMT Daylight Time, UTC+01:00)  #    Disclaimer  |  Comments [0]  | 
# Thursday, August 27, 2009
Interview question -- non-technical about how I handle release problems.
Thursday, August 27, 2009 12:01:11 AM (GMT Daylight Time, UTC+01:00)  #    Disclaimer  |  Comments [0]  | 
# Tuesday, August 25, 2009
An example of reflection in coding!
Tuesday, August 25, 2009 6:12:16 AM (GMT Daylight Time, UTC+01:00)  #    Disclaimer  |  Comments [0]  | 

Today has been an insanely busy day, but I have so much I want to blog about, and this one won't wait. A few days ago, as I was using some code I found on the net, I commented here about the over-use of the var keyword.

Seems I am not the only one who has an opinion on the matter. I subscribe to the CodeProject newsletter, and each issue features a survey. This week, the survey relates to the opinion of the var type in C#. You can see the survey results here. Make sure you click through to the "optional text answers" for some funny comments (and a few relevant ones as well).

The interesting thing to note from the survey is that the answers tend to skew towards the "never use that scenario" range. The two areas where it is most prevalent is with LINQ, and with anonymous types, which makes total sense.

All Things | C# | CSharp | Design | General
Tuesday, August 25, 2009 5:28:04 AM (GMT Daylight Time, UTC+01:00)  #    Disclaimer  |  Comments [0]  |