Hi, I'm a vb.net developer getting the hang of c# and I've gotten stuck on trying to compare types. In the following block, I'm populating an object from a DataTable. The table's data types aren't always the right type so as I loop through I want to compare types and optionally try to convert to make the data match the object property types.
what happens in the above block is I can't even build and Intellisense is flagging the p in p.GetType with this message:
Error 1 The type or namespace name 'p' could not be found (are you missing a using directive or an assembly reference?) ...\Classes\Ite mTreeData.cs 61 55 DAL
Can anyone tell me what I'm doing wrong or have any suggestions for me? Thanks!
Code:
Type t = _Item.GetType();
foreach (DataRow r in dtIT.Rows)
{
foreach (PropertyInfo p in t.GetProperties())
{
//assign any matching column names to object properties
if (dtIT.Columns[p.Name] != null)
{
if (!(r[p.Name].GetType is p.GetType))
{
//convert type if possible
}
p.SetValue(_Item, r[p.Name], null);
}
}
Error 1 The type or namespace name 'p' could not be found (are you missing a using directive or an assembly reference?) ...\Classes\Ite mTreeData.cs 61 55 DAL
Can anyone tell me what I'm doing wrong or have any suggestions for me? Thanks!
Comment