Note: Forums will be making significant UX changes to address key usability improvements surrounding search, discoverability and navigation. To learn more about these changes please visit the announcement which can be found HERE.

Unanswered inserting data using LINQ

  • Monday, November 07, 2011 2:18 PM
     
     

    I have a Web Developer 2010 project with a DataSource called Names.  I have several tables but I started with just the Names table.  I created a LINQ to SQL object and dropped the names table into Names.dbml.  The resulting DataContext was put under my namespace of DataBaseClasses.

    I set up a new datcontext call DB as follows.

    DataBaseClasses.NamesDataContext db = new DataBaseClasses.NamesDataContext;

    But I can't seem to reference any tables;

    I tried:

    var n = from n in db.Names

    {

    var Nam = LastName;

    }

    But I get an error saying db does not exist in the current context.


    Harry T Ulmer

All Replies

  • Monday, November 07, 2011 3:00 PM
     
     

    Hi Harry;

    You are missing the ( and ) at the end of this statement.

    DataBaseClasses.NamesDataContext db = new DataBaseClasses.NamesDataContext;

    Should be :

    DataBaseClasses.NamesDataContext db = new DataBaseClasses.NamesDataContext();

     


    Fernando (MCSD)

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".
  • Monday, November 07, 2011 3:22 PM
     
     

    Sorry.  I put the () at the end so I have

    DataBaseClasses.NamesDataContext db = new DataBaseClasses.NamesDataContext();

    but still get the same error.


    Harry T Ulmer
  • Monday, November 07, 2011 3:37 PM
     
     

     

    Is the NamesDataContext in the same project as where the code that is trying to instantiated it? If no, did you add a reference to the .dll in the project that you are creating the query to the project that has the NamesDataContext?

     


    Fernando (MCSD)

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".
  • Monday, November 07, 2011 4:11 PM
     
     
    Yes.  The dataconmtext is in the same project.
    Harry T Ulmer
  • Monday, November 07, 2011 5:06 PM
     
     

     

    Can you post a screen shot of the Solution Explorer here please.

     


    Fernando (MCSD)

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".
  • Monday, November 21, 2011 1:39 AM
    Moderator
     
     

    Hi harrytu,

    Any updates for your problem?

    Have a nice day.


    Alan Chen[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.