Showing posts with label LINQ. Show all posts
Showing posts with label LINQ. Show all posts

Thursday 3 July 2014

My First Use of Stored Procedures with LINQ to SQL

How to Use Stored Procedures with LINQ to SQL

try
        {
            MyFirstDataClassesDataContext db=new MyFirstDataClassesDataContext();

            var q = from p in db.Test_SD_TrTe_Details_fn("0000000175", "2014", "TR")

                    select new
                    {
                        name = p.Name,Address=p.Address
                    };

            GridView1.DataSource = q;
            GridView1.DataBind();
        }
        catch (Exception ex)
        {
        }

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
            {
               //
            }