Sunday 9 June 2013

In Linq How To Use Sql Query:

 

 

1-Add a new item in your site. Add a LINQ to SQL Classes and name it

DataClasses.dbml.Place this file in the App_Code special folder.

2-From the Server Explorer / Data Explorer window drag the CustomerInfo table and drop it on the DataClasses.dbml.

3-Drag a Gridview web server control on the Default.aspx page. 

4-Write Code Behind button Button6_Click( ).

 

protected void Button6_Click(object sender, EventArgs e)
        {
            try
            {
                DataClassesDataContext dcc = new DataClassesDataContext();
                IEnumerable<CustomerInfo> results1 = dcc.ExecuteQuery<CustomerInfo>  (@"select CustomerId,CustomerName from CustomerInfo");
                GridView2.DataSource = results1;
                GridView2.DataBind();

            }
            catch (Exception ex)
            {
                Response.Redirect(ex.Message);
            }
        }


No comments:

Post a Comment