473,387 Members | 1,465 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

How to get label text from table reference on database based on Table Name

SummaryProblem
=============

How to get label text from table reference on database based on TableName and FieldName dynamically from database and show on view createEmployee .

Details Problem

Meaning i need to get label text dynamically from database not static from model

SO that Every Time i need to change text of label i will change it from database depend on reference table

AND No need to change from code .

===============Goal From I post

I need function or any thing general let me get text of label from database because Title of labels on my suituation changed more)

===============Tools Used

Tools used sql server 2012 and visual studio 2017 asp.net core 2.1


Database Have two tables Employee and Reference File(may be increase models and views so that if any thing general is prefer)
====Code==========
Query Get Data from reference Table

Expand|Select|Wrap|Line Numbers
  1. SELECT TableName, FieldName,EnglishtextforLabel FROM ReferenceFile WHERE (FieldName = 'EmployeeId' ) AND TableName = 'Employee'


Expand|Select|Wrap|Line Numbers
  1. Models classes Include HRContext
  2.  
  3.  public class ReferenceFile(have 3 key as composit keys(Code,TableName,FieldName))
  4.     {
  5.         public int Code { get; set; }
  6.         public string TableName { get; set; }
  7.         public string FieldName { get; set; }
  8.         public string EnglishtextforLabel{ get; set; }
  9.  
  10.     }
  11.  public class Employee
  12.     {
  13.         public int EmployeeId { get; set; }
  14.         public string EmployeeName { get; set; }
  15.         public int EmployeeAge { get; set; }
  16.     }
  17.  public class HRContext : DbContext
  18.     {
  19.         public HRContext(DbContextOptions<HRContext> options)
  20. : base(options)
  21.         { }
  22.  
  23.         public DbSet<Employee> Employees { get; set; }
  24.         public DbSet<ReferenceFile> ReferenceFiles { get; set; }
  25.         protected override void OnModelCreating(ModelBuilder modelBuilder)
  26.         {
  27.             base.OnModelCreating(modelBuilder);
  28.             modelBuilder.Entity<Employee>()
  29.                .HasKey(t => new { t.EmployeeId });
  30.  
  31.             modelBuilder.Entity<ReferenceFile>()
  32.                 .HasKey(t => new { t.Code,t.TableName,t.FieldName });
  33.         }
  34.     }
  35.  
  36.  
  37. Employee View Create(this static and i dont need . i need view labels get from reference table)
  38.  
  39. <div class="row">
  40.     <div class="col-md-4">
  41.         <form asp-action="Create">
  42.             <div asp-validation-summary="ModelOnly" class="text-danger"></div>
  43.             <div class="form-group">
  44.                 <label asp-for="EmployeeName" class="control-label"></label>
  45.                 <input asp-for="EmployeeName" class="form-control" />
  46.                 <span asp-validation-for="EmployeeName" class="text-danger"></span>
  47.             </div>
  48.             <div class="form-group">
  49.                 <label asp-for="EmployeeAge" class="control-label"></label>
  50.                 <input asp-for="EmployeeAge" class="form-control" />
  51.                 <span asp-validation-for="EmployeeAge" class="text-danger"></span>
  52.             </div>
  53.             <div class="form-group">
  54.                 <input type="submit" value="Create" class="btn btn-default" />
  55.             </div>
  56.         </form>
  57.     </div>
  58. </div>
==============
Here i need to get label on view create from table reference not static field name
=======Sample data========
Sample data for ReferenceTable

Expand|Select|Wrap|Line Numbers
  1. Code  TableName  FieldName    EnglishtextforLabel 
  2. 1      Employee  EmployeeId          Code
  3. 2      Employee  EmployeeName        Name        
  4. 3      Employee  EmployeeAge         Age
================
============Result I need==========

labels on view create must be Give me the Result below :

Code

Name

Age
================
Dec 28 '18 #1
3 2877
can any one help me answer question above
Dec 29 '18 #2
AjayGohil
83 64KB
try this code for the C#
Apr 4 '19 #3
AjayGohil
83 64KB
Find the attachment for the code
Attached Files
File Type: docx code.docx (11.9 KB, 108 views)
Apr 4 '19 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: jez123456 | last post by:
Hi, I have the following method where I need to display which database is being processed, however, the label lblDatabase dosn't seem to work until the end. private void...
5
by: Hareth | last post by:
I Tried: If label1.Text < 80 Then lblOutput.Text = "Word I wanna say" It didnt work... Do I have to import something? declare something? missing something?
0
by: phdfromic | last post by:
After a SQL 'select .... from tablename alias' the mysql_fetch_field function returns a value $result=>table which will contain the alias, not the actual table name. Is there a way to get the...
3
by: ASP Developer | last post by:
I have a variety of pages that use a master page. For some reason when I attempt to copy any of the label text on the screen it seems to highlight most of the screen randomly and I can't simply...
4
by: Guy Noir | last post by:
So, I have a table that I only want to appear after some event has fired. Using the asp:table control and the Visible property, this is a piece of cake. The problem is that when I try and drop a...
1
by: radhamohan | last post by:
hii... i m trying to find the Unique key and the foreign key reference in MS-SQL. plz any one advice me how to do this. thank u. radhamohan
3
by: ramakanth05 | last post by:
Hi, I have a problem pulling data from a table using the parameter as table name. I have three tables tbl1, tbl2, tbl3 and I want all the records of the table based on the parameter given. ...
2
by: amwi | last post by:
I have tried to solve this on my own for a long time now, so i really need some help here... I use Oracle 10.1 and SQL *plus 10.1. How do i update table a.fkid from table b.pkid with the...
0
by: vijeta | last post by:
Well, I came across a problem in which based on system selected language, my label text will change. This is called Localization in C#/.Net (Localization is a technique to implement local and...
0
by: Umar Mukhtar | last post by:
I want to use a table name variable in selecting and updating multiple table in mysql database like UPDATE $table_name SET reg_no = ?, name = ?, class = ?, ca1 = ?, ca2 = ?, ca3 = ?, cat = ?, exam =...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.