I’m trying to write a piece of software that will take values from an MSSQL database and put it into a DataGridView, for which the data binding feature of Visual Studio is perfect. The problem is that I want to format/manipulate the information from the database before it gets to the control.
For example, in one database table I have an entry called UserTypeID that contains integers, and another table maps the UserTypeID into a String UserType like “Admin”, “Operator”, “Guest”, etc. I want to be able to take the UserTypeID from the first table, translate it into its String equivalent through the second table, then pass the result on to the DataGridView.
Is there a reasonably simple way to do this, or is something that would require an intermediary object or whatever?
if the strings are static (will not add / delete by the user ) then the easiest way is to create a List<> or an array for the strings and a small extension method like this
and a simple usage example in a Data Access Layer class :
after fill this class you can set as datasource to wherever you want.
but, if your strings are dynamic then you need to create a Stored Proc and call your values from there