* Create new website
* Add new item
→ Select
LINQ TO SQL
classes
Then, create one
dataclasses.dbml file.
Tool→connect to database→ change data source
→ Select datasource (Microsoft sqlserver)
→ Select data provider .NET Framework (data provider for sqlserver)
→ Select servername, SQL authentication and database
→ Select
dataclasses.dbml and we can choose the table and drag into the
dataclasses.dbml file. Class for that Table will be created automatically.
Codes on
default.aspx.cs at code behind page.
private void gridview()
{
DataClassesDataContext dh = new DataClassesDataContext();
var s = from data in dh.tests
orderby data.id descending
select new { data.id ,data.name, data.@class };
GridView1.DataSource = s;
GridView1.DataBind();
}
protected void insert_Click(object sender, EventArgs e)
{
DataClassesDataContext dh = new DataClassesDataContext();
test t = new test { id = Guid .NewGuid ().ToString (),
name =TextBox1 .Text ,
@class = TextBox2 .Text
};
dh.tests.InsertOnSubmit(t);
dh.SubmitChanges();
gridview();
}
protected void update_Click(object sender, EventArgs e)
{
DataClassesDataContext dh = new DataClassesDataContext();
test tt=dh.tests.Single (p1 => p1.name.StartsWith ("manu"));
tt.@class +=4;
tt.name = "raju";
dh.SubmitChanges();
gridview();
}
protected void delete_Click(object sender, EventArgs e)
{
DataClassesDataContext dh = new DataClassesDataContext();
test tt = dh.tests.First(p => p.name.StartsWith("new"));
dh.tests.DeleteOnSubmit(tt);
dh.SubmitChanges();
gridview();
}