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 4625832
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T03:19:47+00:00 2026-05-22T03:19:47+00:00

I got many different SQL tables with the same design – all have identity

  • 0

I got many different SQL tables with the same design – all have identity and two string fields with the same names. I do not want to write a set of functions to get values from these tables, i want to have one procedure with the table as a parameter. But when i start to retrieve data it says “can not convert type bla-bla-bla”. It needs the type to be directly passed and thats what i want to avoid. What to do?

/*
defined tables: 

create table tableA 
(
  id int identity not null,
  type_code nvarchar(50) not null,
  type_description nvarchar(1000) not null
)

same SQL for tableB and tableC

tableA, tableB, tableC
*/

void getAnyId( Table tbl, string codeFilter)
{
   var p=(tableA)tbl;   // HERE I GET EXCEPTION !!!
   var id = p.Where( r=> r.code == codeFilter);
   if( id.Count() != 1 )
       return null;
   return id.id;
}

Another example:

    public Dictionary<string,string> readDataSchemeTypes( tvbaseDataContext dc )
    {
        Dictionary<string,string> ds = new Dictionary<string,string>();

        foreach( var ast in dc.tableA)
            ds.Add( ast.type_code, ast.type_description );

        return ds;
    }

This works but i need a set of functions, one per each table.

public Dictionary<string, string> readAnySchemeTypes<T>(System.Data.Linq.Table<T> table) where T:System.Data.Linq.ITable
{
    Dictionary<string, string> ds = new Dictionary<string, string>();

    foreach (var ast in table)
        ds.Add(ast.type_code, ast.type_description); // type_code and type_description are not defined for type T

    return ds;
}

This example doesn’t compile.

  • 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-22T03:19:47+00:00Added an answer on May 22, 2026 at 3:19 am

    First chance: you can use dynamic SQL to pass table name for each query. But it should be painful because you loss the type-safe of LINQ.
    For example:

    Create procedure s_ProcTable
    @TableName varchar(128)
    as
    
    declare @sql varchar(4000)
        select @sql = 'select count(*) from [' + @TableName + ']'
        exec (@sql)
    go
    

    Once again, be careful with Dynamic SQL. You cannot see any error until you run it

    Second chance: let your method generic. So you just have to specify the type needed for each call, not necessary to re-write the whole method.

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

Sidebar

Related Questions

I have a folder with many images with different backgrounds. I have got requirement
I've got two models, joined by a Has and Belongs To Many join table.
I have tried so many different strategies to get a usable noise function and
I have got many of my questions solved here, many thanks to you guys.
I've got a factor with many different values. If you execute summary(factor) the output
I got a complex question involving many different components of an application. I hope
I've got to design about 5 different classes. A lot of the parts of
I've got many, many mp3 files that I would like to merge into a
I think this should be easy, but it's evading me. I've got a many-to-many
I've got several AssemblyInfo.cs files as part of many projects in a single solution

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.