With that type names (they're not name of classes/structs in System
namespace) one possible solution is to use a Dictionary
. For example (verbose code for illustration purposes):
Dictionary<object, Type> knownTypes = new Dictionary<object, Type>();
knownTypes.Add("bool", typeof(bool));
knownTypes.Add("byte", typeof(byte));
knownTypes.Add("Short", typeof(short));
knownTypes.Add("string", typeof(string));
To be used as:
tblLOG.Columns.Add(row.ItemArray[1].ToString(), knownTypes[row.ItemArray[2]]);
Some changes you may/should consider:
- Make dictionary a
static
andprivate
class member. - Use a typed key for dictionary (using
row.ItemArray[2].ToString()
). - Use a case insensitive comparer
StringComparer.InvariantCultureIgnoreCase
for dictionary key (ifstring
) soshort
andShort
will be equivalent. - Use a similar technique for tables too (
tblLOG
,tblNUMBER
andtblCEMVALVE
) or directly search them using theirTableName
insideDataSet
.