How to use Linq in ASP.NET App refer my below post
http://www.dotnetissues.com/2011/02/select-query-linq-to-sql-example.html
To insert data into DB , below is the code using LINQ
Default7.aspx
http://www.dotnetissues.com/2011/02/select-query-linq-to-sql-example.html
To insert data into DB , below is the code using LINQ
Default7.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default7.aspx.cs" Inherits="Default7" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" runat="server"/>
</div>
</form>
</body>
</html>
Default7.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Default7 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
DataClasses2DataContext db = new DataClasses2DataContext();
//Insert the record
AdminInfo obj = new AdminInfo { sLoginId = "TestLinq", sPassword = "testLinq", dServiceCharge =decimal.Parse ("8.0"), sRoleId = 1, sEmailId = "admin@admin.com" };
db.AdminInfos.InsertOnSubmit(obj);
db.SubmitChanges ();
//Get all the records from table
var results = from o in db.AdminInfos
select o;
GridView1.DataSource = results;
GridView1.DataBind();
}
}
Below 'll be the output after adding the record
No comments:
Post a Comment