cast problem

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
 
A

Alcibiade

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++;
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top