0

I've some data (row) of some table in a db temp that I want to copy on another db (not temp !) but with the same tablename that has the same number, type and order of columns !

So my idea was to create a function to avoid to repeat myself :

public int copyDB(string **tableName**, int[] **id**)
{
    for(int i = 0; i < **id**.Count(); i++)
    {
        var temp = from t in dbtemp.+(**tableName**)+ where t.student_id  == **id**[i]);
    }
    (...)
}

Is it possible to write i function like this? I will just need to call the function where i want to with the correct args.

I'm still looking also how to copy data, I've found some interesting link like this. I still need to try them.

Thanks for your help

Community
  • 1
  • 1
bap
  • 25
  • 1
  • 8
  • 1
    Copying data is just the combination of reading data from a database and saving data to a database. The notation you're using in your sample code is making it pretty confusing, but where specifically are you stuck? Are you able to read data from the first database? Save it to the other database? – David Apr 25 '17 at 15:10
  • 1
    Generally it is possible to write a function like this... – skymon Apr 25 '17 at 15:11
  • 1
    Where is the LINQ in the question? – krillgar Apr 25 '17 at 15:14
  • Ok im confusing you i guess : My first problem is to concat the tablename in the linq query. The tablename is given by arg. Is it possible to make a linq query like "from t in dbtemp.concat(tableName). And of for the copying data, just read and saving to other data i will take a look at this. Thanks :) – bap Apr 25 '17 at 15:15
  • @bap: This might be helpful: https://stackoverflow.com/questions/25859143/linq-select-from-dynamic-tablename-string If it were me, I'd spend less time with reflection on LINQ and just use older ADO.NET queries. If you can secure the values from any user input then there's nothing inherently wrong with building SQL queries from dynamic string values, you just need to control those values. – David Apr 25 '17 at 15:21

0 Answers0