Thursday, 3 July 2014

My First LINQ

            try            {                              
               MyFirstDataClassesDataContext db = new MyFirstDataClassesDataContext();
                var country =from c in db.All_Countries                   
                    select c;
                if (Enumerable.Count(country)>0)
                {                
                    GridView1.DataSource = country;
                    GridView1.DataBind();
                }
                    else
                {
                    GridView1.DataSource = null;
                    GridView1.DataBind();
                }
              
            }
            catch (Exception ex)
            {
                Response.Write(ex.Message);
            }
            finally
            {
               //
            }