Monday, December 3, 2007

Min-height fast hack (IE6 sucks)

Blatantly plagiarized from http://www.dustindiaz.com/min-height-fast-hack/:

selector { min-height:500px; height:auto !important; height:500px;}

Monday, November 5, 2007

T-SQL IP octet split

Found a neat piece of T-SQL that can be used to separate the octets of an IP address:

Declare @IP varchar(20)
Select @IP = '239.147.8.165'
select @IP AS IP,
cast(substring(@IP, 1, charindex('.', @IP) - 1) as int) AS Octet1,
cast(substring(@IP, charindex('.', @IP) + 1,
charindex('.', @IP, charindex('.', @IP) + 1) -
charindex('.', @IP) - 1) as int) as Octet2,
cast(reverse(substring(reverse(@IP), charindex('.', reverse(@IP)) + 1,
charindex('.', reverse(@IP), charindex('.', reverse(@IP)) + 1) -
charindex('.', reverse(@IP)) - 1)) as int) AS Octet3,
cast(reverse(substring(reverse(@IP), 1, charindex('.', reverse(@IP)) - 1)) as int) as Octet4

The source for this is http://www.umachandar.com/technical/SQL6x70Scripts/Main.htm
.

Thursday, October 18, 2007

Auto-refresh an ASPX page

This is especially useful when using a master page but you don't want every page using the master page to refresh.

'Refresh the page every 30 seconds.
Dim lit As New LiteralControl("<meta equiv=""refresh"" content=""30"" />")

Sunday, October 14, 2007

Startup object must be a form when "Enable Application Framework" is checked.

If you're reusing a form and are trying to make it the main form of an application, and you get this error, ensure that the constructor for the form takes no arguments.

Tuesday, August 21, 2007

Programmatically open Access and show a table

Just a note on one way of accomplishing this:

Dim objAccess As Object = CreateObject("Access.Application")
objAccess.OpenCurrentDatabase(strFileName)
objAccess.Visible = True
objAccess.DoCmd.Maximize()
objAccess.DoCmd.OpenTable(strTableName)

Wednesday, August 15, 2007

Console and Windows Form in the same application

I recently needed to write a program that had an attended and unattended mode:

1. Create a console application in Visual Studio .NET.

2. Use this as a template:

Module Module1

Sub Main()

Tuesday, February 13, 2007

Filling in gaps in incrementing INT column in SQL Server

Suppose you have a unique integer column i in a table T. i may contain gaps. i contains m rows.

Suppose you wish to insert n values into i starting at some value x0 and incrementing. Let x equal the first integer greater than or equal to x0 not found in i.

In general, this can be solved by performing the following:

SELECT TOP n * 2 IDENTITY(INT, x, 1) AS j
INTO #temp
FROM T T1
CROSS JOIN T T2
GO

INSERT INTO T (i)
SELECT TOP n j
FROM #temp
LEFT OUTER JOIN T
ON T.i = #temp.j
WHERE T.i IS NULL
GO

There should now be m + n rows in T.

Thursday, January 25, 2007

Getting System Icons into a PictureBox control

A simple solution for getting system icons into a PictureBox control at runtime is to set the PictureBox's Image property to SystemIcons.xxxxxx.ToBitmap().