"If at first you don't succeed; call it version 1.0" :-Unknown

Pages

Wednesday, April 6, 2011

Create a Datatable and schema , A new approach

 Hi *.*,
In my last company my senior always use DATATABLE for Binding, i never seen he using DATASET.Difference i seen , by using tables u need to spend more time on coding,On Dataset it finished !!!. But table is fast than set....Any way i used both in my career depending upon needs.Last day my friend introduce me a new approach to Datatables, in one word i'm impressed.Here i'm presenting both.
Old way


    public void _pre()
    {
        try
        {
            DataTable dt = new DataTable("TableName");
            dt.Columns.Add("MyId"typeof(int));
            dt.Columns.Add("Name");
            dt.Columns.Add("Address");
            DataRow dr = new DataRow();
            dr[0] = 1;
            dr[1] = "Arun Aravind";
            dr[2] = "Kollam,Kerala,India";
            dt.Rows.Add(dr);
        }
        catch (Exception)
        {
           
            throw;
        }
    }

New Method




 
    public void _new()
    {
        try
       {
            DataTable dt = new DataTable
            {
                Columns ={
                {"Myid",typeof(int)},
                {"Name"},
                {"Address"}
                }
            };
            dt.Rows.Add(1, "Arun Aravind""Kollam,Kerala,India");
        }
        catch (Exception)
        {
           throw;
        }
    }
 
Now u compare Both new method is so clean and sexy...Isit???

Hope u got it....Stay Tune... 
Have a nice day... 'N happy Coding :)

No comments: