Thursday, December 1, 2016

Get selected data from datatable in c#

Example
            string StudentName = "foo";
            DataTable dt = new DataTable();
            int id = (from DataRow dr in dt.Rows
                      where (string)dr["StudentName"] == StudentName
                      select (int)dr["id"]).FirstOrDefault();

Example

            DataRow[] result = datatable.Select("age >= 18");
            foreach (DataRow row in result)
            {
                Console.WriteLine("{0}, {1}", row[0], row[1]);
            }

Example
by LINQ
var results = from myRow in myDataTable.AsEnumerable()
where myRow.Field<int>("RowNo") == 1 select myRow;

difference betwen abstract class and virtual class

1. abstract function doesn't contain any body but a virtual function contain body
2. we must be implement the abstract function in derived class but it is not necessary for virtual function
3. abstract function can only use in abstract class but it is not necessary for virtual function
4. abstract function are called pure virtual function