cast problem

  • Thread starter Thread starter Alcibiade
  • Start date Start date
A

Alcibiade

Hi guys,
I have to store some values from an array to a datarow
Sometime I get an error because the type is different that than
expected.
How can I solve?
I wrote this:

foreach (Object obj in array )
{
Type current_type = datarow.GetType();
try
{
datarow = Convert.ChangeType(obj, current_type);
}
catch
{
datarow = obj;
}

i++;

But for example if the expected type of the row is Int32 it doesn't
work.
thanks a lot
 
Alcibiade said:
Hi guys,
I have to store some values from an array to a datarow
Sometime I get an error because the type is different that than
expected.
How can I solve?
I wrote this:

foreach (Object obj in array )
{
Type current_type = datarow.GetType();
try
{
datarow = Convert.ChangeType(obj, current_type);
}
catch
{
datarow = obj;
}

i++;

But for example if the expected type of the row is Int32 it doesn't
work.
thanks a lot


Solved...


foreach (Object obj in array )
{
Object obj2=obj.ToString().Replace("\"","");
Type current_type = datarow.GetType();

try
{
datarow = obj2;
}
catch
{
datarow = DBNull.Value ;
}

i++;
}
 
Back
Top