Performing operations from DataTable c++
C / C++ / MFC
1
Posts
1
Posters
0
Views
1
Watching
-
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); }