I have a project that has dynamic field details for an asp page. When the page is executed, the database is queried for the list of dynamic fields and then all the controls are created at runtime on the asp page. Now all these dynamic fields have corresponding data in another (or say more than one) tables.
The data in the Dynamic Control Detail table is like this:
FieldID | FieldName | MappingTableName | MappingColumnName
-------------------------------------------------------------------------
92 | txtPrsnFirstName | Table1 | FirstName
93 | txtPrsnLastName | Table1 | LastName
94 | ddlPrsnGender | Table2 | Gender
95 | txtCompany | Table2 | Company
96 | txtDesignation | Table1 | Designation
The corresponding datatable's data is as follows:
Table1:
PersonID | FirstName | LastName | Designation
-----------------------------------------
1 | Person1 | SomeName | Manager
2 | Person2 | MoreName | Executive
Table2:
PersonID | Gender | Company
--------------------------------------
1 | Male | ABC Cons
2 | Female | XYZ PVT.LTD
Now, currently what I have done is, created a stored proc, that returns all three tables data at once and I would fetch each one of them in a DataSet
then I would iterate through the FieldTable data first and then fetch the corresponding data from Table1
and Table2
I need to write a query that fetches the data in a way that the data from Table1
and Table2
will get transposed in form of multiple rows (Fetches only one record at a time) something like this.
FieldID | FieldName | MappingTableName | MappingColumnName | Data
---------------------------------------------------------------------------------------
92 | txtPrsnFirstName | Table1 | FirstName | Person1
93 | txtPrsnLastName | Table1 | LastName | SomeName
94 | ddlPrsnGender | Table2 | Gender | Male
95 | txtCompany | Table2 | Company | ABC Cons
96 | txtDesignation | Table1 | Designation | Manager