Subhash Sharma

Subhash Sharma
Subhash Sharma

This is Subhash Sharma(Software Engineer) Blog

Welcome to this blog and find every solution.............

Search This Blog

Software Engineer(Subhash Sharma)

Software Engineer(Subhash Sharma)
Software Engineer

Tuesday, March 1, 2011

LINQ Bind Gridview and Insert Data

SqlConnection con=new SqlConnection (ConfigurationManager.ConnectionStrings["kumarConnectionString"].ConnectionString);

protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
DataClassesDataContext db = new DataClassesDataContext(con);
//linq Table emps
var query = from emp1 in db.emps select new { emp1.id, emp1.Name };
GridView1.DataSource = query;
GridView1.DataBind();
}
}

protected void Button1_Click(object sender, EventArgs e)
{
DataClassesDataContext db = new DataClassesDataContext(con);
db.Connection.Open();
//emp Name of the Table
emp empob = new emp();
empob.Name = TextBox1.Text.Trim();
db.emps.InsertOnSubmit(empob);
db.SubmitChanges();
db.Connection.Close();
TextBox1.Text = "";

}