I have a form and multiple textboxes in it each textbox represents a specific column of a table. for example Textbox of FirstName and its ID='Name' and the column name of Firstname in DB is Name. Now what I am doing is I am sending column value(Whatever user write) and column name (ID of that column) to the function which will save the value in the database.
Here are my steps 1.I get a record on the bases of the DB id which record to update.
var table = _db.Table.Where(x => x.ID == ID).FirstOrDefault();
2.I have all column's names of that table using this.
var names = typeof(User).GetProperties()
.Select(property => property.Name)
.ToArray();
3.Iterated through columns and match that ID of the column with DB Columns if that matches then I have to update that particular column.
foreach (var item in names.ToList())
{
if (item.Equals(ID))
{
table. = TextFieldValue;//here i am stuck
table.Name= TextFieldValue;// i have to update table field like this
}
}
I don't want to use a switch or if-else as there are too many columns in the table.