Blog

LINQ To SQL:Creating a new entity

Posted by Vijai Anand Blogs | LINQ Jun 22, 2011
In this blog we will be seeing how to create a new entity.
EmpDetails Table:

LinqTable.png


Code:


To create a new entity to the EmpDetails table.


using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Text;
namespace
LINQ
{
class Program
{
static void Main(string[] args)
{
DataClassesDataContext dc = new DataClassesDataContext();
EmpDetail newEmp = new EmpDetail();
newEmp.Name =
"Ranjith";
newEmp.Location =
"Mumbai";
newEmp.ID = 8;
newEmp.Dept =
"LN";
newEmp.Allowance = 56300;
dc.EmpDetails.InsertOnSubmit(newEmp);
dc.SubmitChanges();
}
}
}
post comment
     
COMMENT USING
PREMIUM SPONSORS
DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and add new content to existing PDF documents from within your applications.
Get Career Advice from Experts
SPONSORED BY
  • PDF reports have never been easier to create. With our included WYSIWYG Designer, you can layout your reports, set up your data source and let DynamicPDF ReportWriter do the rest.
Get Career Advice from Experts