Posts

Showing posts from May, 2018

Post/Send Anonymous object to MVC/WebAPI Action/Method

I was building an MVC application where we need to give the option to the user to maintain the reference/lookup data through the UI. To active this I created different model and partial views. In order to render the partial view I need to create the different action methods and code wise it will be repetition of code. So I finalized to create one action method that take 2 parameter, the first parameter will tell me the type and second parameter will be object Type. Let me show me how I achieve this with an example. Step 1 – Model namespace WebApplication2.Models.Lookup {     public class User     {         public int UserID { get; set; }         public string UserCode { get; set; }         public string FirstName { get; set; }         public string LastName { get; set; }    ...

Get the Stored Procedure out Parameter value in SSIS using ADO.NET connection

Image
Get the Stored Procedure out Parameter value in SSIS using ADO.NET connection I am new to SSIS and recently I got an assignment to build a SSIS package to load the data in SQL database from flat file. So I created a simple package with dataflow task. Later the requirement slightly got changed and now we need to call some stored proc with OUT PAREMETER those will apply the business logic and transform the data from staging table to main table(s). In order to do this, I added couple of Execute SQL tasks to execute the stored procedure and get the output parameter value. While I was doing this I came to know that based on the connection type your SQL Statement, Parameter Mapping and some other configuration values needs to define in certain ways. I am not going to talk about those in this post. You can find them on this location. Let’s start the step by step process to call the stored process in SSIS using Execute SQL task and get the out parameter value. Step 1 – Add a ...

Reflection In C#

Image
Reflection                 This language feature allows you to inspect the assemblies’ metadata (information of types). Use of Reflection 1.        Late binding 2.        Allow to inspect the content of assembly How to use Reflection public class Program     {         static void Main( string [] args)         {             Type tp = Type .GetType( "ConsoleApplication1.Calculator" );             PropertyInfo [] pInfo = tp.GetProperties();              MethodInfo [] minfo = tp.GetMethods();             //Create Instance ...

Attributes In C#

Image
Attributes – Used to provide the information to compiler about the behavior of class/assemblies and this information can be used by the reflection. Example 1.        Obsolete 2.        WebMethod 3.        Serializable How to use Obsolete Attribute class Program     {         int result = new Calculator ().AddTwoNumbers(1,2);     }         public class Calculator     {         [ Obsolete ( "This method is obsolete, Use new method AddNumbers(List )" )]         public int AddTwoNumbers( int num1, int num2)         {             return num1...

Access Modifier In C#

Access Modifier ·          Public - Access in assembly as well as in reference. Default public access modifier enum, Interface ·          Private - Access within the scope of curly braces ·          Protected - Access in base and derived class ·          Internal - Access within the assembly and within the program that contains its declaration. ·          Protected Internal - Can access anywhere in the same assembly   and inherited class in another assembly. public class Class : Class1     {         public void Method1( int num1)         {             //Public Variable //Accessable in derived class    ...