How to access the ref class declared DataTable ?
-
Hi, I have a small project in VS2010 and its working fine. Now I am trying to upgrade to VS 2015 & Found Visual C++ by using creating project C++/Cli->UI->Windows Forms Applications. I get struck in following simple codes, I cannot identify my mistake.
public ref class My_ProjectData
{
public:
static System::Data::DataTable^ UnitRateTbl = gcnew System::Data::DataTable();public: static void MyUnitRate_Collect() {
String^ ICode=String::Empty;
for(int W1=0; W1<=UnitRateTbl->Rows->Count-1; W1++){
ICode=UnitRateTbl->Rows[W1]["itm_code"]->ToString(); // Error on this line UitRateTbl
}
};
Error : function "System::Data::DataRowCollection::default[int]::get" cannot be called with the given argument listThanks for the helps
-
Hi, I have a small project in VS2010 and its working fine. Now I am trying to upgrade to VS 2015 & Found Visual C++ by using creating project C++/Cli->UI->Windows Forms Applications. I get struck in following simple codes, I cannot identify my mistake.
public ref class My_ProjectData
{
public:
static System::Data::DataTable^ UnitRateTbl = gcnew System::Data::DataTable();public: static void MyUnitRate_Collect() {
String^ ICode=String::Empty;
for(int W1=0; W1<=UnitRateTbl->Rows->Count-1; W1++){
ICode=UnitRateTbl->Rows[W1]["itm_code"]->ToString(); // Error on this line UitRateTbl
}
};
Error : function "System::Data::DataRowCollection::default[int]::get" cannot be called with the given argument listThanks for the helps
-
I have looked at the documentation and cannot see an error in that line of code. However, I notice that you have declared
UnitRateTbl
asstatic
, and wonder if that may be the problem.Thank Richard, I checked by Without static declaration, but still the error raised. I assume that, we have to supply the datatype to that for loop variable [W1].[May be Not sure]
String^ ICode=String::Empty;
for(int W1=0; W1<=UnitRateTbl->Rows->Count-1; W1++){
ICode=UnitRateTbl->Rows[W1]["itm_code"]->ToString(); ??????????????
}Thanks Again
-
Thank Richard, I checked by Without static declaration, but still the error raised. I assume that, we have to supply the datatype to that for loop variable [W1].[May be Not sure]
String^ ICode=String::Empty;
for(int W1=0; W1<=UnitRateTbl->Rows->Count-1; W1++){
ICode=UnitRateTbl->Rows[W1]["itm_code"]->ToString(); ??????????????
}Thanks Again
-
That will not help since the data type is already defined in your
for
expression. You could try breaking the statement into its parts:DataRow row = UnitRateTbl->Rows[W1];
ICode= row["itm_code"];... and see what happens.
Thank Richard