26 November 2008

"Renaming" fields within table

Today I have to change the name of one column within my ms sql database.
I wanted to come up with the script that will do it for me.
I figured that ms sql discourage use of altering column names, rather they want you to drop and then recreate column using following sql:


ALTER TABLE TableName DROP COLUMN ColumnName

ALTER TABLE TableName ADD ColumnName datatype NULL


I haven't spent much time exploring further possibility of "renaming" column that exists with oracle. If something like this is possible with ms sql 2005 I would like to hear?

21 November 2008

Visual Studio Search & Replace (Multiple Lines)

After spending some time figuring out how to find and replace multiple line content across multiple files, I figured that VS 08 that I'm using offer this functionality.
This functionality is very powerful due to regular expressions.
Regular expressions seem very confusing and complicated at the first glance, but are very very powerful.

Here is a sample of what I did:
//match this
private void Page_Load\(object sender, System.EventArgs e\)\n.*\{\n:b*if \(!IsAuthenticated\(\)\)\n:b*Server\.Transfer\(GetAppSetting\(GlobalConstants\.NOT_AUTHENTICATED_KEY\)\);

Couple of things worth remembering:
1. \n.* matches zero or more line breaks
2. \ escape any special character as bracket (
3. :b matches space or tab

//replace with this
if (!IsAuthenticated())\n\t\t\t\tServer.Transfer(GetAppSetting(GlobalConstants.NOT_AUTHENTICATED_KEY));\n\n\t\t\tUserRole role = GetUserRole();\n\t\t\tswitch (role)

Hope I'll have more time to play with regular expression since this is extremely powerful concept.

Links:
1. regex library cheat shit :-)
2. msdn regular expression builder

07 November 2008

Deleting controls (possible active) on excel sheet

Today I had to send list of items in excel sheet.
As usual I would come up with the list by coping data from web page and pasting it into excel sheet. But what if you copy some control altogether with the data?
After I manually deleted couple of hundred right on excel sheet :-(, I figured I might be able to automates the process of deleting those hated cheque boxes.
As usual I was right, soon after I sent my excel (without cheque boxes of course)


Link: Deleting controls programmatic.