LINQ Insert Query:
tbl_student stu = new
tbl_student();
stu.Name = txt_name.Text.Trim();
db.tbl_students.InsertOnSubmit(stu);
db.SubmitChanges();
Before Table data
Asp.net Code
<form id="form1" runat="server">
<div>
<center>
<table>
<tr>
<td>
Name:
</td>
<td>
<asp:TextBox ID="txt_name" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
</td>
<td>
<asp:Button ID="btn_submit" runat="server" Text="Submit"
onclick="btn_submit_Click"
/>
</td>
</tr>
</table>
</center>
</div>
</form>
C#.net Code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Insert :
System.Web.UI.Page
{
protected void
Page_Load(object sender, EventArgs e)
{
}
protected void
btn_submit_Click(object sender, EventArgs e)
{
MydbDataContext db = new
MydbDataContext();
tbl_student stu = new
tbl_student();
stu.Name = txt_name.Text.Trim();
db.tbl_students.InsertOnSubmit(stu);
db.SubmitChanges();
}
}
After Table data
(Output):
No comments:
Post a Comment