Click here to Skip to main content
15,887,083 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
How to get fields exist on table by passing table name ?

suppose I have table name Employee on SQL server 2012

and this is fields of Employee Table EmployeeCode,EmployeeName,,..etc

How to make function pass to it table name and it will retrieve fields or columns as

EmployeeCode,

EmployeeName

I work on web API core project with angular 7

structure of function as below

What I have tried:

public List<string> GetColumnNames(string tablename)
{
}
Posted
Updated 10-Mar-19 5:59am

1 solution

The ANSI SQL query statement for this is:
SQL
SELECT Column_Name FROM Information_Schema.Columns WHERE Table_Name = 'tableName'
 
Share this answer
 
Comments
ahmed_sa 10-Mar-19 12:07pm    
i know that but cannot do that by entityframework core 2.1
so that how to do that by cshap
ahmed_sa 10-Mar-19 12:13pm    
how to do that by entity framework core 2.1
ahmed_sa 10-Mar-19 12:14pm    
my function structure as above
MadMyche 10-Mar-19 13:21pm    
I would recommend reading up on EF database first methods.
https://www.c-sharpcorner.com/article/asp-net-co-crud-using-angular-5-and-entity-framework/

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900