Tuesday, October 26, 2010

Trying Out Amazon Associates

For the first time I'm going to try and monetize this site.

Wednesday, October 20, 2010

Old School WScript to Make Files Read-Write

If you frequently need to change the file attributes of one or more files from "Read Only" to "Read and Write" on Windows (like I have to do when dealing with the limitation of Visual SourceSafe), this quickie script will do the trick. Create a .vbs file with the following:

Set objFSO = CreateObject("Scripting.FileSystemObject")
Dim arrayFileObjects(1)
set arrayFileObjects(0) = objFSO.GetFile("C:\BudgetTracker\App.config")
set arrayFileObjects(1) = objFSO.GetFile("C:\ApeSim\App.config")

for counter = 0 to ubound(arrayFileObjects)
if arrayFileObjects(counter).Attributes AND 1 then
'read-only, so set to read/write
arrayFileObjects(counter).Attributes = arrayFileObjects(counter).Attributes XOR 1
Wscript.echo ("one changed")
Wscript.echo ("one already ok")
End If


Tuesday, October 19, 2010

VB.NET, DB Nulls, and strings

If you are dealing with a database that isn't enforcing "no nulls" then you may frequently get nulls back when you are expecting a string. Although you could do this:

if dr.Item("middle_name") is DBNull.Value then
txtMiddleName.Text = ""

It is easier to just write:

txtMiddleName.Text = dr.Item("middle_name").ToString

because adding "ToString" will convert nulls to "" empty strings.
If you omit the "ToString", any nulls will generate an error (converting a Null to a String).

Monday, October 18, 2010


The syntax for inserting a new row (or record) into a table using data from a select is not very intuitive.

The INSERT syntax is:
INSERT tblFred(field1, field2, field3) VALUES( 'ape', 436, 0)
or if you are insert values for all columns in order:
INSERT tblFRED VALUES (23, 'ape', 436, 0)

But to use the INSERT with a SELECT, you omit the VALUES( ) phrase:
INSERT tblFred(field1, field2, field3) SELECT fieldA, fieldB, fieldC FROM tblSmedly

INSERT tblFred SELECT * FROM tblSmedly

Friday, October 15, 2010

Which edition of SQL Server 2005 is that?

SELECT SERVERPROPERTY('productversion'), SERVERPROPERTY ('productlevel'), SERVERPROPERTY ('edition')

Tuesday, October 12, 2010

UNIX Date Format for SQL Server

UNIX date times are most often stored as seconds from midnight, January 1, 1970. If you are running into a date format that looks like, for example, "1286790650" or "1141541097", a ten digit number, it is most likely a UNIX time stamp. (also see http://en.wikipedia.org/wiki/Unix_time ).

Here's how to convert on SQL Server:
dateadd(ss, 1234567890, '1970-01-01')
where 12345678790 is your date given in UNIX time stamp format.

This is also why 11:31 pm (in the UK) was so exciting on February 13, 2009.