cannot convert parameter 2 from 'int' to 'int'

G

Gary

I have a strange compile error. C2664 cannot convert parameter 2 from int to
int...

Earlier in my code I was setting up my dataset...

I add an int field like so...

Books->Columns->Add("Volume",System::Type::GetType(S"System.Int32"));

Then below I try to add an int value to it.

Nr->Item[S"Volume"] = Volume;

(Nr is a new Datarow of the table "books"

And get this error:

error C2664: 'void System::Data::DataRow::set_Item(int,System::Object __gc
*)' : cannot convert parameter 2 from 'int' to 'int'

I checked to see if it was because the column and the variable have the same
name but setting it to the value 1 also caused the same error.

What am I doing wrong?
 
T

Tomas Restrepo \(MVP\)

Gary,
I have a strange compile error. C2664 cannot convert parameter 2 from int
to int...

Earlier in my code I was setting up my dataset...

I add an int field like so...

Books->Columns->Add("Volume",System::Type::GetType(S"System.Int32"));

A simpler way is:
Books->Columns->Add("Volume", __typeof(int));

Then below I try to add an int value to it.

Nr->Item[S"Volume"] = Volume;

The problem here is that the compiler gets confused because of overloads of
the Item property. A simple way to get what you want is to simply box the
volume:

Nr->Item[S"Volume"] = __box(Volume);
 

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