logo
down
shadow

How to get JSON response for column names in database table


How to get JSON response for column names in database table

Content Index :

How to get JSON response for column names in database table
Tag : chash , By : eastcoastj
Date : November 24 2020, 05:48 AM

I hope this helps you . Answer
So I have added a new controller class which is a custom class not dependent on the DB. I have also added a new route to the WebApiConfig.cs file. As well as a new "template" class. Here is what I have.
config.Routes.MapHttpRoute(
name: "FieldValues",
routeTemplate: "api/FieldValues/id",
defaults: new { controller = "FieldValues"}
);
    public class FieldValues
    {
        public string COLUMN_NAME { get; set; } //this "variables" name is same as in query. Note: if the set is not present nulls would be returned
    }
    public class FieldValuesController : ApiController
    {
        private CoreGradingDBEntities db = new CoreGradingDBEntities();

        [Route("api/FieldValues/id")]
        public IList<FieldValues> Get(string id)
        {
            var response = db.Database.SqlQuery<FieldValues>("SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = '" + id + "' ORDER BY ORDINAL_POSITION").ToList();
            return response;
        }
    }

[{"$id":"1","COLUMN_NAME":"ID"},{"$id":"2","COLUMN_NAME":"DepartmentID"},{"$id":"3","COLUMN_NAME":"PermissionID"},{"$id":"4","COLUMN_NAME":"Username"},{"$id":"5","COLUMN_NAME":"PasswordHash"},{"$id":"6","COLUMN_NAME":"PasswordResetToken"},{"$id":"7","COLUMN_NAME":"TokenValid"},{"$id":"8","COLUMN_NAME":"Email"},{"$id":"9","COLUMN_NAME":"EmailConfirmed"},{"$id":"10","COLUMN_NAME":"PhoneNumber"},{"$id":"11","COLUMN_NAME":"PhoneNumberConfirmed"},{"$id":"12","COLUMN_NAME":"TwoFactorEnabled"},{"$id":"13","COLUMN_NAME":"AccessFailedCount"},{"$id":"14","COLUMN_NAME":"LocoutEndDate"},{"$id":"15","COLUMN_NAME":"LockoutEnabled"}]
api/FieldValues/id?id={id}

api/FieldValues/id?id=Account //the 'Account' can be replaced by your table name you wish to get the values from


Comments
No Comments Right Now !

Boards Message :
You Must Login Or Sign Up to Add Your Comments .

Share : facebook icon twitter icon

List all index names, column names and its table name of a PostgreSQL database


Tag : postgresql , By : Yolanda N. Ceron
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further This will output all indexes with details (extracted from my view definitions):
SELECT i.relname as indname,
       i.relowner as indowner,
       idx.indrelid::regclass,
       am.amname as indam,
       idx.indkey,
       ARRAY(
       SELECT pg_get_indexdef(idx.indexrelid, k + 1, true)
       FROM generate_subscripts(idx.indkey, 1) as k
       ORDER BY k
       ) as indkey_names,
       idx.indexprs IS NOT NULL as indexprs,
       idx.indpred IS NOT NULL as indpred
FROM   pg_index as idx
JOIN   pg_class as i
ON     i.oid = idx.indexrelid
JOIN   pg_am as am
ON     i.relam = am.oid;
SELECT i.relname as indname,
       i.relowner as indowner,
       idx.indrelid::regclass,
       am.amname as indam,
       idx.indkey,
       ARRAY(
       SELECT pg_get_indexdef(idx.indexrelid, k + 1, true)
       FROM generate_subscripts(idx.indkey, 1) as k
       ORDER BY k
       ) as indkey_names,
       idx.indexprs IS NOT NULL as indexprs,
       idx.indpred IS NOT NULL as indpred
FROM   pg_index as idx
JOIN   pg_class as i
ON     i.oid = idx.indexrelid
JOIN   pg_am as am
ON     i.relam = am.oid
JOIN   pg_namespace as ns
ON     ns.oid = i.relnamespace
AND    ns.nspname = ANY(current_schemas(false));

How to create a column containing a JSON that has names defined from the value of a column in another table?


Tag : sql , By : mylonov
Date : March 29 2020, 07:55 AM
Hope this helps I have a source table with data in VARCHAR format like the example below. I want to insert the data in another table in a JSON format (the result column itself can be of JSON or VARCHAR type). , You can remove the unwanted parts using a RegEx:
SELECT
   SourceTable.Id
  ,RegExp_Replace(Cast(Json_Agg(SourceTable.JSONName AS "#A",SourceTable.JSONValue AS "#B") AS VARCHAR(32000)), '"#A":|,"#B"|^\[|\]$|}(?=,{")|(?<="},){')
FROM SourceTable
GROUP BY 1
'"#A":|,"#B"|^[|]$|}(?=,)|(?<=,){'

how to retrieve values of numeric column names of table from vue axios response


Tag : vue.js , By : user87225
Date : March 29 2020, 07:55 AM
seems to work fine Use bracket notation:
axios.get('/someAPIpage/').then(response => {
  this.name = response.data[0].name;
  this.a1 = response.data[0]['1'];
  this.a2 = response.data[0]['2'];
  this.a3 = response.data[0]['3'];
  this.a4 = response.data[0]['4'];
});

Checked the query, database, table names, column names, etc. Still have no idea why this error occurred


Tag : php , By : PeteFilicetti
Date : March 29 2020, 07:55 AM
I hope this helps . Solved after I changed the variables that contained string value with this format -> ' " . $variable . " ' .

Using constants for message keys and database table names and column names


Tag : development , By : Ir0nh1de
Date : March 29 2020, 07:55 AM
Related Posts Related QUESTIONS :
  • How to get record form a different table based on a value from first table with linq expression?
  • Show data in Grid from returned model
  • Using Attributes to Override Data Model Conventions
  • Basic OOP console calculator, result Error
  • Compositon and Repository pattern
  • Multiple using statements with if condition
  • How do i increase a number by 1 in every line that contain the number 1
  • Add binding to elements that are created in codebehind
  • How to add a column in an existing AspNetUsers table
  • Order a list of elements with another list of doubles
  • How to setup a NuGet package to copy content files to output build directory?
  • In SignalR Core using ChannelWriter: Do I need to call TryComplete twice if there's an exception?
  • C# GetProcessesByName: issue with colon
  • c# wpf | create complex object with user-defined name to Serialize into JSON
  • How can I get a instance of a generic list with reflection?
  • WPF XAML - Design time and visibility of textbox
  • EF Core and MySql query is too slow
  • Getting Registered App Display Name from an App Id
  • How to get all variables from a string
  • Delete entity with all childs connected
  • Azure Build agent cant´t find class library referance
  • Initialize Nested Dictionaries in c#
  • .Net Core Binding
  • Generic event test method, preventing code duplication
  • How do I keep the ellipses in the center when the screen is resized
  • How to require a property using JsonSchema.NET?
  • C# XDocument Element/Elements returns null
  • Autofac keyed service with IEnumerable relationship type
  • Installing EntityFramework via NuGet manager
  • Always Check if there is Internet Connection Xamarin forms
  • WCF OneWay service slows down when aspNetCompatibilityEnabled is set to false
  • Can we use JsonRequestBehavior.AllowGet with [HttpPost] attribute?
  • How to customize the Setup wizard with custom forms in Visual Studio setup project
  • C# ASP.NET - Use method from another class to create labels
  • C# List IList or IEnumerable as argument
  • Parsing File with C# And Replace method
  • Losing special unicode characters in encryption (C#)
  • Getting stored procedure returned value instead of row affected
  • How can I construct HTML using NameValuePair in android?
  • Loading a pop up page in ASP.net through a js file
  • How to pass alert or notification message from controller to View?
  • C# to pause, turn on ssas server, backup cube.... how to?
  • How to execute DataTable.Select() for a column of custom class type for a particular element in that C#
  • how to connect mysql8.0 with C#
  • Passing incorrect values into MultiValueConverter by MultiBinding
  • Can i use IEnumerator as Update func?
  • How to convert API Json response to C# Array?
  • Blazor Textfield Oninput User Typing Delay
  • Performing both layout and render transform results in wrong output
  • uwp beforetextchanged cursor moving in front of text
  • How to keep duplicates from a string[] exclude words from a List and print them out
  • .Net Core Strings.Asc/Mid/Chr/Len missing even after importing Microsoft.VisualBasic
  • How to return to previous search page without being asked to Confirm Form Re-submission and keeping the results on ASP.N
  • How set a identity scaffolding item/page how initial page in asp.net MVC core?
  • LINQ isn't calling Dispose on my IEnumerator when using Union and Select, expected behavior or bug?
  • What is "ByteArray.uncompress()" in AS3 equivalent to in C#?
  • Getting a specific letter from a string variable for my simple guessing game for clues
  • Send an email with Outlook without a subject --- dialog box issue
  • passing List<MyModel> from my controller in the "WebInterfaceProject" to the processor method in "D
  • How to convert Word document created from template by OpenXML into MemoryStream?
  • shadow
    Privacy Policy - Terms - Contact Us © scrbit.com