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

  • SEARCH
  • Home
  • 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 6590601
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T17:19:14+00:00 2026-05-25T17:19:14+00:00

//Instead of the this var tableX = db.PRODUCT; //db is the DataContext //I can

  • 0
        //Instead of the this 
        var tableX = db.PRODUCT; //db is the DataContext
        //I can do the below (Thanks to http://stackoverflow.com/questions/1919632/get-table-data-from-table-name-in-linq-datacontext
        string tablename = "PRODUCT";
        var table = (ITable)db.GetType().GetProperty(tablename).GetValue(db, null);

        //But instead of this
        PRODUCT _Product = new PRODUCT();
        _Product.PRD_CODE = "code1";
        _Product.PRD_DESC = "description1";
        table.InsertOnSubmit(_Product);
        db.SubmitChanges();

        //How can I do something like this
        string tablename = "PRODUCT";
        var table = (ITable)db.GetType().GetProperty(tablename).GetValue(db, null);
        string lsColumnPrdCode = "PRD_CODE";
        string lsColumnPrdDesc = "PRD_DESC";
        table _tableInstance = new table();
        _tableInstance[lsColumnPrdCode] = "code1";
        _tableInstance[lsColumnPrdDesc] = "description1";
        _tableInstance.InsertOnSubmit(_tableInstance);
        db.SubmitChanges();

So it is possible to set datacontext column values without strongly typing it?

  • 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-25T17:19:15+00:00Added an answer on May 25, 2026 at 5:19 pm

    Of cause you can use reflection to do that kind of stuff. Maybe something similar to this code:

    Type productType = Type.GetType("PRODUCT");
    var product = Activator.CreateInstance(productType);
    productType.GetProperty("PRD_CODE").SetValue(product, "code1");
    productType.GetProperty("PRD_DESC").SetValue(product, "description1");
    
    Type tableType = table.GetType();
    tableType.GetMethod("InsertOnSubmit").Invoke(table, new object[] {product});
    

    But why do you want to do that?

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

Sidebar

Related Questions

Why this returns false instead of true. function doit(expression) { var regex = new
$('a').live('click',function(e){ e.preventDefault(); var id = $(this).attr('id'); infowindow2.open(map, marker2); // I need instead of 2
Is there any get() function for this instead? {% for key, value in choices.items
Can I copy only the error message from Eclipse Problems with instead of this
I need to get table data from table name from Linq DataContext. Instead of
UPDATE : I do appreciate don't want that, want this instead suggestions. They are
Let's say I have a model class called Project, but instead of this: class
Do you think that C# will support something like ??= operator? Instead of this:
Is it possible to instead of doing this: person.Walking -= person_Walking1; person.Walking -= person_Walking2;
Why is this creating a new row at the bottom with this data instead

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.