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. C / C++ / MFC
  4. Performing operations from DataTable c++

Performing operations from DataTable c++

Scheduled Pinned Locked Moved C / C++ / MFC
c++question
1 Posts 1 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.
  • U Offline
    U Offline
    User 11196121
    wrote on last edited by
    #1

    Hi all Might I ask some advice/fixes on the below code, as I am still not familiar with referencing multiple columns from DataTable in c++ yet? Confused | :confused: Your inputs would be much appreciated. Thanks in advance.

    MySqlCommand^CmdDataBase = gcnew MySqlCommand("select * from world.city",conDataBase);
    try{
    conDataBase->Open();
    MySqlDataAdapter^sda= gcnew MySqlDataAdapter();
    sda->SelectCommand=CmdDataBase;
    DataTable^dbdataset=gcnew DataTable();
    DataColumn^rt_col=gcnew DataColumn();
    rt_col->ColumnName = "Ret";
    rt_col->DataType=System::Type::GetType("System.Double");
    dbdataset->Columns->Add(rt_col);

    				 DataRow^rt\_row;
    				 
    				 for (int row=0;dbdataset->Rows->Count;row++)				 
    				 {
    					 rt\_row=dbdataset->NewRow();
    					 rt\_row\["Ret"\]=System::Convert::ToDouble(rt\_row\["Population"\])/System::Convert::ToDouble(rt\_row\["Population"\]);
    				     //rt\_row\["DataReturn"\]=System::Convert::ToDouble(dbdataset->Rows\[row\]\["Population"\])/System::Convert::ToDouble(dbdataset->Rows\[row-1\]\["Population"\]);
    					 dbdataset->Rows->Add(rt\_row);
    					 
    				 }
    				 
    				 sda->Fill(dbdataset);	
    				 BindingSource^bSource=gcnew BindingSource();
    				 bSource->DataSource=dbdataset;
    				 dtGrid->DataSource=bSource;
    			 
    			 } 
    			 catch(Exception^ex) {
    				 MessageBox::Show(ex->Message);
    	 }
    
    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