Sai Stuff to Developers

October 1, 2013

Launched New Technology Site developersfusion.com

Hi Friends,

I have recently launched a new Technology WebSite www.developersfusion.com .

 

About Developers Fusion

Developers Fusion is a place where the professionals can share their experience and views contributing knowledge to the developer’s community. A successful professional, learns, explores, matures and finally contributes.

The developersfusion.com works with an idea, that has a big vision of bringing Technology to the cozy of your room wherever you are, and make learning comprehensive and exploring Technology real simple and easy.

We are dedicated in providing our Readers quality implementation, education, documentation and solutions. Our ultimate goal is to provide our readers with appropriate solution to their technical questions and needs. The developersfusion.com personifies the passion for Software Technology, delivers power in the technology and the skills associated with it, and enhances the productivity of professionals who shape the software field.

The developersfusion.com believes that it is vital to make learning Technology easy and effective and help its readers, technical breakthroughs in their future career along with other sessions that make them more informed about things that happen around them.

The Articles section lists articles published from different professionals enabling our readers to learn what’s new in the market and also the experience of the author. The FAQs section enables readers to prepare for answering the interview questions shot at them.

Our Vision

Bringing Technology to the cozy of every developer room wherever you are, and make learning comprehensive and exploring Technology real simple and easy.

Our Goal

Our ultimate goal is to provide our readers with appropriate solution to their technical questions and needs.

 

Hope all you make my new website a grand success by visiting posting and participating in forums etc…,

 

Regards,

Sai Kumar K

May 3, 2012

Converting DataTable to a List of Entity Object

Filed under: DotNet,LINQ — tosaik @ 12:30 pm
Tags: , , , , ,

Recently some one asked me how should i need to convert a DataTable to an List of Entity Object. Let me Explain in detail below…

Let say we have following Entity Class called Testimonial with two properties i.e.., Comment and Commentedby here Comment is the property where we have the actual comment by the User and Commentedby is the property to store the name of the User who commented it.

 public class Testimonial
    {
        public string Comment { get; set; }
        public string Commentedby { get; set; }
    }

Now we need to get these Testimonial data from data source it may be from Database / XML file / CSV File etc.., we use XML file for this example . Now using linq we Enumerate the collection of dataRows in the datatable and create a list of Testimonials as shown below

List<Testimonial> lstTestimonial = new List<Testimonial>();

 string strpath = System.IO.Path.Combine(AppDomain.CurrentDomain.GetData(“DataDirectory”).ToString(), “Testimonials.xml”);
            DataSet ds = new DataSet();
            ds.ReadXml(strpath);

            if (ds != null && ds.Tables.Count > 0)
            {
                lstTestimonial = (from r in ds.Tables[0].AsEnumerable()
                                  select new Testimonial
                                  {
                                      Comment = r.Field<string>(“Comment”),
                                      Commentedby = r.Field<string>(“Commentedby”)
                                  }).ToList<Testimonial>();
            }

Note this is the best way to convert because due to strong data-type using Field Method, we can rectify any type conversion issues at Compile time.

Hope this short explanation (due to insufficient time) Helps you… Please comment me in any case…

Happy Coding 🙂

 

 

April 12, 2012

Adding a new record to an IQueryable variable

Filed under: LINQ — tosaik @ 7:09 am
Tags: ,

Hi All,

Recently working on one of my application using Linq, i need to fill the datagridview with selected rows and columns which i can get from querying a list of objects using Linq. Now for every result i need to add an additional static record to the grid view. for this i need to have this record as a last record for my selected IQueryable variable from LINQ result.  Let me show you through example what i said till now…

Ex:

var varresult = from r in lstobject select new { COLUMN1 = r.Title, COLUMN2 = r.Price };

DataGridView1.datasource = varresult ;

DataGridView1.databind();

Now i need to add a new static record (i.e.., new{COLUMN1=”Discount Price”, COLUMN2=10}) to the existing varresult object…

varresult  = varresult.ToList().Union(new[] { new{COLUMN1=”Discount Price”, COLUMN2=10}});

DataGridView1.datasource = varresult ;

DataGridView1.databind();

 

thats it Now a last record will be what you want… Please note that the variables and there types should be same as result object had.

Hope this Helps u…

 

Happy Coding 🙂

 

 

 

 

 

Create a free website or blog at WordPress.com.

%d bloggers like this: