Head.SmackOnTable();

Contains Nuts.

Archive for July, 2009

Output all properties for any object

without comments


private void outputValues(object inputObject)
{
List<PropertyInfo> propertyInfos = new List<PropertyInfo>(inputObject.GetType().GetProperties());

foreach (PropertyInfo info in propertyInfos)
{
try
{
object obj = info.GetValue(inputObject, null);
if (obj == null)
{
continue;
}
Console.WriteLine("[{0}]:{1}", info.Name, obj.ToString());

}
catch (Exception)
{
continue;
}

}

}

Replace the Console.WriteLine with whatever you want, log4net,Ā  Debug, trace, etc, and it works!

Written by Monty

July 22nd, 2009 at 9:51 am

Posted in Code Snippet

Tagged with ,

Clearing FK’s and tables from database

without comments

SELECT 'ALTER TABLE ' +  OBJECT_NAME(f.parent_object_id) + ' DROP CONSTRAINT [' + f.name + ']' FROM sys.foreign_keys AS f INNER JOIN sys.foreign_key_columns AS fc ON f.OBJECT_ID = fc.constraint_object_id
union all
SELECT 'DROP TABLE '+ name FROM dbo.sysobjects WHERE (type = 'u') and name != 'sysdiagrams'

Written by Monty

July 14th, 2009 at 4:45 pm

Posted in Misc