in Education by
I want to make a method that will populate the lst_List list with rows from various tables and fields. Preliminary version of the code: cntDB = new ContextDB(); List> lst_List = new List>(); public void Method_2(string nameTable, string nameField) { var phones = cntDB.Database.ExecuteSqlCommand("SELECT " + nameField + " FROM " + nameTable); // +- lst_List.AddRange(phones.ToList()); } How to make the method fill the list with values from different tables and fields in one list? JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
ExecuteSqlCommand returns an int not the result set and is used primarily for non-SELECT commands (e.g. INSERT, UPDATE, DELETE). Use SqlQuery instead: cntDB = new ContextDB(); List lst_List = new List(); public void Method_2(string nameTable, string nameField) { var lst_List = cntDB.Database.SqlQuery("SELECT " + nameField + " FROM " + nameTable).ToList(); } You don't get a List> this way but I can't see how you will populate that type from a single flat query as per your SQL statement?

Related questions

0 votes
    I want to make a method that will populate the lst_List list with rows from various tables and fields. ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 24, 2022 in Education by JackTerrance
0 votes
    I am trying to concatenate two fields from a list to display in a dropdown. Below is the code i ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 27, 2022 in Education by JackTerrance
0 votes
    I am trying to call a method from the script Dice and after that method is executed the value of ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 2, 2022 in Education by JackTerrance
0 votes
    I have 2 Tables, Receipts which contains columns like Id, InvoiceId etc and Invoices, which Contains Id, ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 10, 2022 in Education by JackTerrance
0 votes
    I have 2 Tables, Receipts which contains columns like Id, InvoiceId etc and Invoices, which Contains Id, ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 7, 2022 in Education by JackTerrance
0 votes
    I have a div and, inside it, an unordered list with several list items that serve as navigation menu ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 7, 2022 in Education by JackTerrance
0 votes
    In an application I'm developing, someone thought it would be ok idea to include commas in the values ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 11, 2022 in Education by JackTerrance
0 votes
    In an application I'm developing, someone thought it would be ok idea to include commas in the values ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 11, 2022 in Education by JackTerrance
0 votes
    In an application I'm developing, someone thought it would be ok idea to include commas in the values ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 11, 2022 in Education by JackTerrance
0 votes
    first of all,i am fairly new with spring mvc so .. how springmvc find the right class to ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 17, 2022 in Education by JackTerrance
0 votes
    Thinking like a simple array: Console.WriteLine("Number: "); int x = Convert.ToInt32(Console.ReadLine()) ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 17, 2022 in Education by JackTerrance
0 votes
    Thinking like a simple array: Console.WriteLine("Number: "); int x = Convert.ToInt32(Console.ReadLine()) ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 13, 2022 in Education by JackTerrance
0 votes
    Thinking like a simple array: Console.WriteLine("Number: "); int x = Convert.ToInt32(Console.ReadLine()) ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 13, 2022 in Education by JackTerrance
0 votes
    Thinking like a simple array: Console.WriteLine("Number: "); int x = Convert.ToInt32(Console.ReadLine()) ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 7, 2022 in Education by JackTerrance
...