Subscribe to Subscribers
Talk to Webmaster Tony John

Online Members

Vinod
More...

Forums » .NET » LINQ »

Linq doubt with stored procedure


Posted Date: 22 Jul 2012      Posted By:: naresh     Member Level: Silver    Member Rank: 987     Points: 2   Responses: 1



Hi i created one procedure for insert values in table . Now i want to insert values using linq in asp.net how to do this.can any one tell me how to insert step by step



Responses

#681347    Author: Ajatshatru Upadhyay      Member Level: Gold      Member Rank: 19     Date: 22/Jul/2012   Rating: 2 out of 52 out of 5     Points: 4

Hi,

If you are using LINQ, you don't even need an INSERT command or a sp for this. you can use "InserOnSubmit()" method of DataContext class for the same.

Below is an example, in which I am inserting a new record to "Region" table of "Northwind" database on button click.
My dbml file name is "Northwind.dbml".


protected void Button1_Click(object sender, EventArgs e)
{
NorthwindDataContext db = new NorthwindDataContext();
Region rgn = new Region();
rgn.RegionID = 1100;
rgn.RegionDescription = "Added from LinqToSql";

db.Regions.InsertOnSubmit(rgn);

try
{
db.SubmitChanges();
}
catch (Exception ex)
{
Label2.Text = ex.ToString();
}
Label2.Text = "Successfully inserted!!!";
}


Hope it'll help you.
Regards
Ajatshatru



 
Post Reply
You must Sign In to post a response.

Next : Get all tables from database and loop through each table using C#,linq query and entity fr
Previous : Unable To resolve problem
Return to Discussion Forum
Post New Message
Category:

Related Messages
Active Members
TodayLast 7 Daysmore...

Awards & Gifts
Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India
2005 - 2012 All Rights Reserved.
.NET and other trademarks mentioned in this site belong to Microsoft and other respective trademark owners.
Articles, tutorials and all other content offered here is for educational purpose only.
We are not associated with Microsoft or its partners.