Querying data in a database
usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingsystem.web;usingSystem.Web.UI;usingSystem.Web.UI.WebControls;usingSystem.Configuration;usingSystem.Data;usingSystem.Data.SqlClient; Public Partial class_default:system.web.ui.page{protected voidPage_Load (Objectsender, EventArgs e) {Dataclassesdatacontext lqdb=NewDataclassesdatacontext (configurationmanager.connectionstrings["db2016connectionstring"]. Connectionstring.tostring ()); varresult = fromRinchlqdb.newswhereR.id >0 SelectR; Gridview1.datasource=result; Gridview1.databind (); }}
Adding data to the database
usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingsystem.web;usingSystem.Web.UI;usingSystem.Web.UI.WebControls;usingSystem.Configuration; Public Partial class_default:system.web.ui.page{protected voidPage_Load (Objectsender, EventArgs e) { } protected voidButton1_Click (Objectsender, EventArgs e) {Linqdbdatacontext lqdb=NewLinqdbdatacontext (configurationmanager.connectionstrings["db2016connectionstring"]. Connectionstring.tostring ()); News Info=NewNews (); Info.content=TextBox1.Text; LqDB.news.InsertOnSubmit (info); Lqdb.submitchanges (); Page.ClientScript.RegisterStartupScript (GetType (),"","alert (' Publish Success '); Location.href= ' Default.aspx '",true); }}
modifying data
protected voidPage_Load (Objectsender, EventArgs e) {Linqdbdatacontext lqdb=NewLinqdbdatacontext (configurationmanager.connectionstrings["db2016connectionstring"]. Connectionstring.tostring ()); varresult = fromRinchlqdb.newswhereR.id = =1 SelectR; foreach(News Info1inchresult) {info1.content="There's nothing I can't do, I'm the best"; } lqdb.submitchanges (); }
Delete data
New Linqdbdatacontext (configurationmanager.connectionstrings["db2016connectionstring" ]. Connectionstring.tostring ()); var from inch lqdb.news where 1 Select R; LqDB.news.DeleteAllOnSubmit (result); Lqdb.submitchanges ();
Add, modify, delete, and query operations for ASP. NET LINQ Connection database SQL execution data