Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Managed C++/CLI
  4. How to access the ref class declared DataTable ?

How to access the ref class declared DataTable ?

Scheduled Pinned Locked Moved Managed C++/CLI
c++visual-studiowinformsdesignhelp
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    Paramu1973
    wrote on last edited by
    #1

    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 list

    Thanks for the helps

    L 1 Reply Last reply
    0
    • P Paramu1973

      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 list

      Thanks for the helps

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      I have looked at the documentation and cannot see an error in that line of code. However, I notice that you have declared UnitRateTbl as static, and wonder if that may be the problem.

      P 1 Reply Last reply
      0
      • L Lost User

        I have looked at the documentation and cannot see an error in that line of code. However, I notice that you have declared UnitRateTbl as static, and wonder if that may be the problem.

        P Offline
        P Offline
        Paramu1973
        wrote on last edited by
        #3

        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

        L 1 Reply Last reply
        0
        • P Paramu1973

          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

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          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.

          P 1 Reply Last reply
          0
          • L Lost User

            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.

            P Offline
            P Offline
            Paramu1973
            wrote on last edited by
            #5

            Thank Richard

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups