Showing posts with label Console Application. Show all posts
Showing posts with label Console Application. Show all posts

Tuesday, 14 November 2017

Convert Object to DataTable in C#


Converting object to datatable using the C# code, it help in many places like doing the bulk insertion of data to database. There we need to send data in the form of table.
Suppose we have an Employee Class.

public class Employee
    {
        public int EmployeeId { get; set; }
        public string EName { get; set; }
        public int Age { get; set; }
        public decimal Salary { get; set; }
    }

Now instead of creating method for converting the object to datable, we will create a generic extension method which will convert any type of object into datatable.
public static class Utility

Thursday, 7 July 2016

Console application pass parameters

Target of application to be like calculator, you will pass the string like n1+n2-n3/n4*n5 and it will calculate the value and give the result. e.g. 2+2-2*2/2 will give the result as 2