Posts

Execute method in C# using reflection

namespace MyCompany { [TestFixture] public class Test { [Test] public void Test1() { MyClass obj = new MyClass(); MethodInfo m = obj.GetType().GetMethod(" Test "); m.Invoke(obj, null ); } public class MyClass { public void Test() { Console.WriteLine(" Test "); } } }

Create object from name in C# like class.forName in java

If you have a project with the assemblyName MyCompany.MyAssemblyName And the Class defined in some namespace. You can create an object from class name and assembly name information. namespace MyCompany.MyAssemblyName.MyNamespace { [TestFixture] public class Test { [Test] public void Test1() { MyClass obj = (MyClass)Activator.CreateInstance(" MyCompany.MyAssemblyName "," MyCompany.MyAssemblyName.MyNamespace.MyClass ").Unwrap(); obj.Test(); } } public class MyClass { public void Test() { Console.WriteLine(" Test "); } } }

Create Windows Service application in C#

- Create 'Windows Application' Project - Add 'Windows Service' item to your project - Add 'Installer Class' item to your project - Set the service name/description using the property editor or inside *.designer.cs classes Installing Windows Service c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\InstallUtil.exe Program.exe Uninstalling Windows Service c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\InstallUtil.exe \uninstall Program.exe

How to Insert data to a table with only Identity Column

DECLARE @Table1 TABLE( Column1 INT IDENTITY(1,1) PRIMARY KEY ) INSERT INTO @Table1 DEFAULT VALUES SELECT * FROM @Table1

Windows Remote Desktop on multiple screens

To get the multiple screen support on Windows XP download the latest (6.0 or above) ' Remote Desktop Connection ' software from Microsoft website. And run the following command mstsc /span /v:"pc-name" Here you can find more info about mstsc command

Could not find file 'Microsoft.Windows.CommonLanguageRuntime, Version=2.0.50727.0'

Could not find file 'Microsoft.Windows.CommonLanguageRuntime, Version=2.0.50727.0' If you get this error go through your projects in the solution and uncheck 'Enable ClickOnce Security Settings' on Properties/Security. This is sometimes happening when you by mistake click Publish on the project.

SQL Server pivoting data with dynamic sql

Example of how to dynamically generate sql statement to PIVOT data in SQL Server 2005 and above. You can put this code into stored procedure and use it instead of a view. I'm not aware of any alternative to that approach as you can't call stored procedure from the view and you can't dynamically define return table columns for table-valued functions. CREATE TABLE #Attributes ( id INT , name VARCHAR (50), value VARCHAR (50), dt DATETIME ); INSERT INTO #Attributes VALUES (1,' Field1 ', ' A ', ' 20080701 '); INSERT INTO #Attributes VALUES (2,' Field1 ', ' B ', ' 20080701 '); INSERT INTO #Attributes VALUES (3,' Field1 ', ' C ', ' 20080701 '); INSERT INTO #Attributes VALUES (3,' Field2 ', ' X ', ' 20080701 '); INSERT INTO #Attributes VALUES (4,' Field1 ', ' D ', ' 20080702 '); INSERT INTO #Attributes VALUES (4,' Field2 ', ' X ...