NovelProjects

Saturday, December 20, 2008

Code for newline in C#

I always have trouble remembering things and I'm always looking for shortcuts. The other day I was wanting to replace the newline constant in a string with an html break tag and I found Environment.NewLine for C#.


You should try it.

Thursday, April 10, 2008

Delete Similar Records

To delete similar records, i.e. where the records are not the same but one field is the same and only one copy needs to be preserved, try the following SQL:



delete from T1
from MyTable T1, MyTable T2
where T1.dupField = T2.dupField
and T1.uniqueField > T2.uniqueField


This will delete all records from the table MyTable which have the same value for the field dupField, leaving that record which has the lowest value in uniqueField.

Wednesday, March 5, 2008

Reinitialize MS SQL DB Identity

Sometimes you'll find the need to reinitialize your identity column in a database back to a certain value. Maybe the values are higher than you would like and you want to start back at a lower range. Or perhaps you've deleted all the data and would like the table to start indexing at a lower value. The command to do this in Microsoft's SQL is "DBCC CHECKIDENT (tablename, reseed, reinitialize to this value)".



DBCC CHECKIDENT (TestTable, reseed, 15) would start the indexing at the value 15 for TestTable.

Monday, February 4, 2008

Setup ASP.NET Membership and Roles

Using Windows authentication you would type the following command to have Windows automatically setup the tables for ASP.NET Membership:



C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_regsql.exe -E -S server\instanceName -A mr -d database


Using SQL authentication type:



C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_regsql.exe -U user -P password -S server\instanceName -A mr -d database