Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6781537
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T16:38:08+00:00 2026-05-26T16:38:08+00:00

I read a set of data from database first Insert a new record using

  • 0
  • I read a set of data from database first
  • Insert a new record using same data in same table.

I tried this but:-

using (var db = new
    DataContext(ConfigurationManager.ConnectionStrings["DB"].ToString()))
{
    var items = from t in db.Table1
                where t.ID.Equals(100)
                select t;
    foreach (var item in items)
    {
        using (var db1 = new
            DataContext(ConfigurationManager.ConnectionStrings["DB"].ToString()))
        {
            Table1 tab = new Table1
            {
                FName = item.FName,
                LName = item.LName,
                Number = item.Number,
            };
            db1.Table1.InsertAllOnSubmit(tab);
            db1.SubmitChanges();
        }
    }
}

I can’t compile it. It throws this error at line ‘db1.Table1.InsertAllOnSubmit(tab)‘:-

‘System.Data.Linq.Table.InsertAllOnSubmit(System.Collections.Generic.IEnumerable)’
cannot be inferred from the usage. Try specifying the type arguments
explicitly.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T16:38:09+00:00Added an answer on May 26, 2026 at 4:38 pm

    Your code has some flaws.

    You seem to read one Table1 (assuming the id is unique) but you are treating it like a collection

    Quick try since you anyway add only one table1 at a time: Replace

    db1.Table1.InsertAllOnSubmit(tab); 
    

    by

    db1.Table1.InsertOnSubmit(tab); 
    

    If your ID is not unique try:

    List<Table1> items = (from t in db.Table1 
                where t.ID.Equals(100) 
                select t).ToList();
    

    The rest of the code can stay the same (but still replace the InsertAllOnSubmit)

    Update

    You can simplify bigtime:

    using (var db = new 
    DataContext(ConfigurationManager.ConnectionStrings["DB"].ToString())) 
     { 
    Table1 thisTable = (from t in db.Table1 
                where t.ID. == 100
                select t).SingleOrDefault(); 
    
    if ( thisTable != null)
    {
            Table1 tab = new Table1 ()
            { 
                FName = item.FName, 
                LName = item.LName, 
                Number = item.Number,                }; 
                db.Table1.InsertOnsubmit(tab)
                db.SubmitChanges(); 
             }
     } 
    }
    

    if you are 100% sure your id will always match use .Single() instead of .SingleOrDefault(). Single will throw an exception if no result matches. SingleOrDefault returns NULL in this case.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am attempting to read a MySQL database from my C# project using the
I have a database and i can insert into it and read from it
What is the best way to read and/or set Internet Explorer options from a
While trying to connect to a database that's set to read only, the connection
Because of legacy data which is not available in the database but some external
I'm importing data from a CSV file that comes from excel, but i can't
I read an article and its comments from mysql database with two separate queries
I have some status data that I want to cache from a database. Any
My application loads lots of data from a database into a complex data structure.
I have to return data fetched from MySQL table into a php file as

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.