locked
insert using LinqToSql RRS feed

  • Question

  • insert into table1 (Wicket,Run,Catch) values (Wicket+2,Run+22,Catch+5)

    This statement is used to insert data using StoredProcedure. How can i insert data same way without using storeprocedure but using LinqToSql. What will be code for it.


    markand

    Monday, December 17, 2012 4:26 PM

Answers

  • Hi MarkandBhatt;

    In order to use Linq to SQL you need to have created a data model that can be instantiate into a DataContext. Please see the following article which shows how to create the model and how to make some queries.

    Using LINQ to SQL (Part 1)

    He has about 5 or 6 other articles on the as subject. If you do a search on his web site using the phrase "Using Linq to SQL (Part " it should come up with the others.

      


    Fernando (MCSD)

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".

    • Marked as answer by Alexander Sun Wednesday, December 26, 2012 2:46 AM
    Tuesday, December 18, 2012 12:49 AM

All replies

  • Hi MarkandBhatt;

    In order to use Linq to SQL you need to have created a data model that can be instantiate into a DataContext. Please see the following article which shows how to create the model and how to make some queries.

    Using LINQ to SQL (Part 1)

    He has about 5 or 6 other articles on the as subject. If you do a search on his web site using the phrase "Using Linq to SQL (Part " it should come up with the others.

      


    Fernando (MCSD)

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".

    • Marked as answer by Alexander Sun Wednesday, December 26, 2012 2:46 AM
    Tuesday, December 18, 2012 12:49 AM
  • Hi,

    See Fernando Soto response if you are new to Linq to Sql (though in this case you may want to consider Linq to Entity Framework). If you already have a model, try to explain what you are trying to do as the statement you show shouldn't even work (column names in the values clause are not legal).

    My guess is that you try perhaps to read the last added entity, and use those values for the newly inserted entity (by adding a constant to them) ?


    Please always mark whatever response solved your issue so that the thread is properly marked as "Answered".

    Tuesday, December 18, 2012 6:27 PM